Kaggle competition: Categorical Feature Encoding Challenge
<SOS> metric: AUC Kaggle data source: categorical-feature-encoding-challenge<compute_test_metric>
import pandas as pd
import category_encoders as ce
from sklearn import linear_model
from sklearn.model_selection import StratifiedKFold
r2_score(y_val_exp,y_pred_val_exp )<install_modules>
train = pd.read_csv('.. /input/cat-in-the-dat/train.csv')
 test = pd.read_csv('.. /input/cat-in-the-dat/test.csv')
 train.sort_index(inplace=True)
 train_y = train['target']
test_id = test['id']
train.drop(['target', 'id'], axis=1, inplace=True)
 test.drop('id', axis=1, inplace=True )
!pip install pydotplus<feature_engineering>
cat_feat_to_encode = train.columns.tolist()
smoothing=50.0
oof = pd.DataFrame([])
 for tr_idx, oof_idx in StratifiedKFold(
 n_splits=5, random_state=1, shuffle=True ).split(
 train, train_y):
ce_target_encoder = ce.TargetEncoder(cols = cat_feat_to_encode, smoothing=smoothing)
 ce_target_encoder.fit(train.iloc[tr_idx, :], train_y.iloc[tr_idx])
 oof = oof.append(ce_target_encoder.transform(train.iloc[oof_idx, :]), ignore_index=False)
 ce_target_encoder = ce.TargetEncoder(cols = cat_feat_to_encode, smoothing=smoothing)
 ce_target_encoder.fit(train, train_y)
 train = oof.sort_index()
test = ce_target_encoder.transform(test )
def draw_tree(model, columns):
graphviz_path = 'C:\Program Files(x86)\Graphviz2.38/bin/'
os.environ["PATH"] += os.pathsep + graphviz_path
dot_data = StringIO()
tree.export_graphviz(model,
out_file=dot_data,
feature_names=columns)
 graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
 return Image(graph.create_png() )<merge>
glm = linear_model.LogisticRegression(
 random_state=1, solver='lbfgs', max_iter=5000, fit_intercept=True,
penalty='none', verbose=0)
 glm.fit(train, train_y )
<merge><EOS> 
pd.DataFrame({'id': test_id, 'target': glm.predict_proba(test)[:,1]} ).to_csv(
 'sub_' + str(datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) + '.csv',
index=False )