Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FranciscusRenatus/224d1b3ec257246af325c3012816da2a to your computer and use it in GitHub Desktop.
Save FranciscusRenatus/224d1b3ec257246af325c3012816da2a to your computer and use it in GitHub Desktop.
# Encoding categorical data
# Encoding the Independent Variable
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X = LabelEncoder()
X[:, 0] = labelencoder_X.fit_transform(X[:, 0])
onehotencoder = OneHotEncoder(categorical_features = [0])
X = onehotencoder.fit_transform(X).toarray()
#Avoiding dummy variable trap
X = X[:, 1:]
# Encoding the Dependent Variable
labelencoder_y = LabelEncoder()
y = labelencoder_y.fit_transform(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment