Created
January 8, 2019 03:35
-
-
Save finnqiao/c6f57c34fec8ce287be724154f005075 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Label Encode instead of dummy variables | |
mappings = [] | |
from sklearn.preprocessing import LabelEncoder | |
label_encoder = LabelEncoder() | |
label_df = df.drop('y', axis=1) | |
for i, col in enumerate(label_df): | |
if label_df[col].dtype == 'object': | |
label_df[col] = label_encoder.fit_transform(np.array(label_df[col].astype(str)).reshape((-1,))) | |
mappings.append(dict(zip(label_encoder.classes_, range(1, len(label_encoder.classes_)+1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment