Kaggle competition: Categorical Feature Encoding Challenge
<SOS> metric: AUC Kaggle data source: categorical-feature-encoding-challenge<init_hyperparams>
import pandas as pd
import category_encoders as ce
import lightgbm as lgb
from sklearn.model_selection import StratifiedKFold
params_1 = {
'task': 'train',
'boosting_type': 'gbdt',
'objective': 'binary',
'learning_rate': x_1[0],
'num_leaves': x_1[1],
'min_data_in_leaf': x_1[2],
'num_iteration': x_1[3],
'max_bin': x_1[4],
'verbose': 1
}
params_2 = {
'task': 'train',
'boosting_type': 'gbdt',
'objective': 'binary',
'learning_rate': x_2[0],
'num_leaves': x_2[1],
'min_data_in_leaf': x_2[2],
'num_iteration': x_2[3],
'max_bin': x_2[4],
'verbose': 1
}
gbm_1 = lgb.train(params_1,
train_data,
num_boost_round=1000,
valid_sets=test_data,
early_stopping_rounds=100)
 gbm_2 = lgb.train(params_2,
train_data,
num_boost_round=1000,
valid_sets=test_data,
early_stopping_rounds=100 )<compute_train_metric>
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 )
confidence_test =(gbm_1.predict(X_test)+ gbm_2.predict(X_test)) /2
confidence_test =(confidence_test-confidence_test.min())/(confidence_test.max() -confidence_test.min())
 confidence_test = confidence_test*2-1
print(max(confidence_test),min(confidence_test))
r_test = r_test.clip(-1,1)
 x_t_i = confidence_test * r_test * u_test
data = {'day' : d_test, 'x_t_i' : x_t_i}
df = pd.DataFrame(data)
 x_t = df.groupby('day' ).sum().values.flatten()
mean = np.mean(x_t)
 std = np.std(x_t)
 score_test = mean / std
print(score_test )<define_variables>
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 )
days = env.get_prediction_days()
n_days = 0
prep_time = 0
prediction_time = 0
packaging_time = 0
total_market_obs_df = []<define_variables>
clf = lgb.train(
 params={
'max_depth': 2,
'num_leaves': 150,
'reg_alpha': 0.6,
'reg_lambda': 0.6,
'objective': 'binary',
"boosting_type": "gbdt",
"metric": 'auc',
"verbosity": -1,
'random_state': 1},
train_set=lgb.Dataset(train, label=train_y),
num_boost_round=700 )
<define_variables><EOS> 
pd.DataFrame({'id': test_id, 'target': clf.predict(test)} ).to_csv(
 'sub_' + str(datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) + '.csv',
index=False )