Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Levente Endre Nádai
Added: Jan 5, 2020 7:17 PM
Views: 12
  1. # Encoding categorical data
  2. # Encoding the Independent Variable
  3. from sklearn.preprocessing import LabelEncoder, OneHotEncoder
  4. labelencoder_X = LabelEncoder()
  5. X[:, 0] = labelencoder_X.fit_transform(X[:, 0])
  6. onehotencoder = OneHotEncoder(categorical_features = [0])
  7. X = onehotencoder.fit_transform(X).toarray()
  8. # Encoding the Dependent Variable
  9. labelencoder_y = LabelEncoder()
  10. y = labelencoder_y.fit_transform(y)