There are two types of encoding the Categorical Data:
- One Hot Encoding
- Label Encoding or Target Encoding
Example:
One Hot Encoding – 100, 101, 010
Label Encoding – Normal = 0, Malicious = 1
# Encoding categorical data
# Encoding the Independent Variable
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [0])], remainder='passthrough')
X = np.array(ct.fit_transform(X))
print(X)
# Encoding the Dependent Variable
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
y = le.fit_transform(y)
print(y)




