Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

one hot encoder python

from sklearn.preprocessing import OneHotEncoder
encoder = OneHotEncoder()
# apply on df
color_1hot = encoder.fit_transform(df['ocean_proximity'].values.reshape(-1,1))
color_1hot_df = pd.DataFrame(color_1hot.toarray())
df = pd.concat([df.drop('ocean_proximity', axis=1), color_1hot_df], axis=1)
# can allso use the pandas dummies
df = pd.get_dummies(df, columns=['ocean_proximity'])

# apply on np.array
X[:, 2] = le.fit_transform(X[:, 2])
 
PREVIOUS NEXT
Tagged: #hot #encoder #python
ADD COMMENT
Topic
Name
7+9 =