Kaggle competition: Santander Customer Transaction Prediction
train_X['month']=train_X['month_id']%12+1<feature_engineering>
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv' )
train_X['shop_months_since_opening']=train_X['month_id']-train_X['shop_id'].map(train_X[['month_id','shop_id']].groupby('shop_id' ).min() ['month_id'])
 train_X['shop_opening']=(train_X['shop_months_since_opening']==0 )<feature_engineering>
train_df.isnull().values.any()
train_X['item_month_id_of_release']=train_X['item_id'].map(train_X[['month_id','item_id']].groupby('item_id' ).min() ['month_id'])
 train_X['item_month_of_release']=train_X['item_month_id_of_release']%12+1
train_X['item_months_since_release']=train_X['month_id']-train_X['item_month_id_of_release']
train_X['item_months_since_release'].clip(0,12,inplace=True)
 train_X['item_new']=(train_X['item_months_since_release']==0 )<feature_engineering>
features = [c for c in train_df.columns if c not in ['ID_code', 'target']]
target = train_df['target']
train_X=train_X.join(train_agg[['shop_id','month_id','item_id']].groupby(['shop_id','item_id'] ).min().rename({'month_id':'item_month_id_of_first_sale_in_shop'},axis=1),on=['shop_id','item_id'])
 train_X['item_month_of_first_sale_in_shop']=train_X['item_month_id_of_first_sale_in_shop']%12+1
train_X['item_months_since_first_sale_in_shop']=(train_X['month_id']-train_X['item_month_id_of_first_sale_in_shop'])
 train_X['item_months_since_first_sale_in_shop'].clip(0,12,inplace=True)
 train_X['item_never_sold_in_shop_before']=~(train_X['item_months_since_first_sale_in_shop']>0)
 train_X.loc[train_X['item_never_sold_in_shop_before'],'item_months_since_first_sale_in_shop']=-1
train_X.loc[train_X['item_never_sold_in_shop_before'],'item_month_id_of_first_sale_in_shop']=-1
train_X.loc[train_X['item_never_sold_in_shop_before'],'item_month_of_first_sale_in_shop']=-1
train_X['item_months_since_first_sale_in_shop']=train_X['item_months_since_first_sale_in_shop'].astype(np.int8)
 train_X['item_month_id_of_first_sale_in_shop']=train_X['item_month_id_of_first_sale_in_shop'].astype(np.int8)
 train_X['item_month_of_first_sale_in_shop']=train_X['item_month_of_first_sale_in_shop'].astype(np.int8 )<data_type_conversions>
param = {
'bagging_freq': 5,
'bagging_fraction': 0.33,
'boost_from_average':'false',
'boost': 'gbdt',
'feature_fraction': 0.05,
'learning_rate': 0.01,
'max_depth': -1,
'metric':'auc',
'min_data_in_leaf': 80,
'min_sum_hessian_in_leaf': 10.0,
'num_leaves': 13,
'num_threads': 12,
'tree_learner': 'serial',
'objective': 'binary',
'verbosity': 1
}
train_X['item_never_sold_in_shop_before_but_not_new']=(( 1-train_X['item_new'])*train_X['item_never_sold_in_shop_before'] ).astype(bool )<data_type_conversions>
num_round = 100000
folds = StratifiedKFold(n_splits=12, shuffle=False, random_state=12345)
 oof = np.zeros(len(train_df))
predictions = np.zeros(len(test_df))
train_X['item_seniority']=(2-train_X['item_new'].astype(int)-train_X['item_never_sold_in_shop_before'].astype(int)).astype(np.int8 )<feature_engineering>
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train_df.values, target.values)) :
print("Fold {}".format(fold_))
trn_data = lgb.Dataset(train_df.iloc[trn_idx][features], label=target.iloc[trn_idx])
 val_data = lgb.Dataset(train_df.iloc[val_idx][features], label=target.iloc[val_idx])
 clf = lgb.train(param, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=1000, early_stopping_rounds = 2500)
 oof[val_idx] = clf.predict(train_df.iloc[val_idx][features], num_iteration=clf.best_iteration)
 predictions += clf.predict(test_df[features], num_iteration=clf.best_iteration)/ folds.n_splits
print("CV score: {:<8.5f}".format(roc_auc_score(target, oof)) )
<merge><EOS> 
submission = pd.DataFrame({"ID_code": test_df.ID_code.values})
 submission["target"] = predictions
submission.to_csv("submission.csv", index=False )