Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
y = trn[TARGET_COL].values
n_trn = trn.shape[0]
trn.drop(TARGET_COL, axis=1, inplace=True)
cat_cols = [x for x in trn.columns if trn[x].dtype == np.object]
num_cols = [x for x in trn.columns if trn[x].dtype != np.object]
logging.info('categorical: {}, numerical: {}'.format(len(cat_cols),
len(num_cols)))
df = pd.concat([trn, tst], axis=0)
logging.info('label encoding categorical variables')
lbe = LabelEncoder(min_obs=10)
df[cat_cols] = lbe.fit_transform(df[cat_cols])
df[num_cols] = df[num_cols].fillna(-1)
with open(feature_map_file, 'w') as f:
for i, col in enumerate(df.columns):
f.write('{}\t{}\tq\n'.format(i, col))
logging.info('saving features')
save_data(df.values[:n_trn,], y, train_feature_file)
save_data(df.values[n_trn:,], None, test_feature_file)