Kaggle competition: Santander Customer Transaction Prediction
<SOS> metric: AUC Kaggle data source: santander-customer-transaction-prediction<define_variables>
warnings.filterwarnings('ignore' )
split_col='month_id'
target_col='item_quantity'
raw_features=[]
label_encoding=['shop_id',
'item_id',
'item_category_id',
'item_supercategory_id',
'item_category_console_id',
'item_category_is_digital'
]
mapping_columns=[]
features_to_discard=['item_id',
'shop_id',
'item_supercategory_id',
'item_category_console_id',
'item_category_is_digital'
]
features_to_discard+=mapping_columns
raw_features+=['shop_months_since_opening']
raw_features+=['shop_opening']
raw_features+=['item_category_freq']
raw_features+=['item_supercategory_freq']
raw_features+=['item_category_console_freq']
raw_features+=['item_category_digital_freq']
raw_features+=['item_category_freq_in_seniority']
raw_features+=['item_supercategory_freq_in_seniority']
raw_features+=['item_category_console_freq_in_seniority']
raw_features+=['item_category_digital_freq_in_seniority']
raw_features+=['category_semiannual_avg_recent_rsd']
raw_features+=['category_semiannual_avg_annual_rsd']
train_0=train_0[[split_col]+label_encoding+mapping_columns+[target_col]+raw_features]
print(train_0.info(null_counts=True))
gc.collect()<load_pretrained>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )
shop_category_prices=pd.read_pickle(os.path.join(DATA_FOLDER,'processed/price_features/shop_category_prices.pkl'))
category_prices=pd.read_pickle(os.path.join(DATA_FOLDER,'processed/price_features/category_prices.pkl'))
supercategory_prices=pd.read_pickle(os.path.join(DATA_FOLDER,'processed/price_features/supercategory_prices.pkl'))<create_dataframe>
i = 1
for df in [test, train]:
idx = df.columns.values[i:i+200]
df['sum'] = df[idx].sum(axis=1)
 df['min'] = df[idx].min(axis=1)
 df['max'] = df[idx].max(axis=1)
 df['mean'] = df[idx].mean(axis=1)
 df['std'] = df[idx].std(axis=1)
 df['skew'] = df[idx].skew(axis=1)
 df['kurt'] = df[idx].kurtosis(axis=1)
 df['med'] = df[idx].median(axis=1)
 i = i + 1
ts = time.time()
price_features_df=[]
price_features_df.append(moving_statistics(train_0,shop_category_prices,['month_id','shop_id','item_category_id'],['shop_category_price_median'],34,'mean',suffix='_absolute_mean'))
price_features_df.append(moving_statistics(train_0,shop_category_prices,['month_id','shop_id','item_category_id'],['shop_category_price_median'],3,'mean',suffix='_recent_mean'))
price_features_df.append(lag_features(train_0,shop_category_prices,['month_id','shop_id','item_category_id'],['shop_category_price_median'],[12]))
price_features_df.append(moving_statistics(train_0,category_prices,['month_id','item_category_id'],['category_price_min'],34,'min',suffix='_absolute_min'))
price_features_df.append(moving_statistics(train_0,category_prices,['month_id','item_category_id'],['category_price_max'],34,'max',suffix='_absolute_max'))
price_features_df.append(moving_statistics(train_0,category_prices,['month_id','item_category_id'],['category_price_min'],12,'min',suffix='_annual_min'))
price_features_df.append(moving_statistics(train_0,category_prices,['month_id','item_category_id'],['category_price_max'],12,'max',suffix='_annual_max'))
price_features_df.append(moving_statistics(train_0,category_prices,['month_id','item_category_id'],['category_price_median'],3,'mean',suffix='_recent_mean'))
price_features_df.append(lag_features(train_0,category_prices,['month_id','item_category_id'],['category_price_median'],[12]))
price_features_df.append(moving_statistics(train_0,category_prices,['month_id','item_category_id'],['category_price_median_compared_to_supercategory_price_median'],34,'mean',suffix='_absolute_mean'))
price_features_df.append(moving_statistics(train_0,supercategory_prices,['month_id','item_supercategory_id'],['supercategory_price_median'],3,'mean',suffix='_recent_mean'))
price_features_df.append(lag_features(train_0,supercategory_prices,['month_id','item_supercategory_id'],['supercategory_price_median'],[12]))
print('time : ' +str(time.time() - ts))
train_0=pd.concat([train_0]+price_features_df,axis=1,sort=False)
 del price_features_df
gc.collect()
print('time : ' +str(time.time() - ts))
train_0=downcast_dtypes(train_0)
 print('time : ' +str(time.time() - ts))
print(train_0.info(null_counts=True))
train_0<drop_column>
def augment(x,y,t=2):
xs,xn = [],[]
for i in range(t):
mask = y>0
x1 = x[mask].copy()
ids = np.arange(x1.shape[0])
 for c in range(x1.shape[1]):
np.random.shuffle(ids)
 x1[:,c] = x1[ids][:,c]
xs.append(x1)
 for i in range(t//2):
mask = y==0
x1 = x[mask].copy()
ids = np.arange(x1.shape[0])
 for c in range(x1.shape[1]):
np.random.shuffle(ids)
 x1[:,c] = x1[ids][:,c]
xn.append(x1)
 xs = np.vstack(xs)
 xn = np.vstack(xn)
 ys = np.ones(xs.shape[0])
 yn = np.zeros(xn.shape[0])
 x = np.vstack([x,xs,xn])
 y = np.concatenate([y,ys,yn])
 return x,y
del shop_category_prices
del category_prices
del supercategory_prices
gc.collect()<load_pretrained>
dfs=['shop_encoding',
'category_encoding',
'supercategory_encoding',
'shop_category_encoding',
'shop_supercategory_encoding'
]
for df in dfs:
exec(df+"=pd.read_pickle(os.path.join(DATA_FOLDER,'processed/target_encodings/"+df+".pkl')) ")
 exec(df+"_seniority_0=pd.read_pickle(os.path.join(DATA_FOLDER,'processed/target_encodings/"+df+"_seniority_0.pkl')) " )<statistical_test>
features = [c for c in train.columns if c not in ['ID_code', 'target']]
target = train['target']
feature_correlation_analysis(train_0,supercategory_encoding,supercategory_encoding_seniority_0,'supercategory',['month_id','item_supercategory_id'],0)
 compare_features(supercategory_encoding,supercategory_encoding_seniority_0,'supercategory',['month_id','item_supercategory_id'],0,20,6,20 )<statistical_test>
param = {
'bagging_freq': 5,
'bagging_fraction': 0.4,
'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': 28,
'tree_learner': 'serial',
'objective': 'binary',
'verbosity': 1}
feature_correlation_analysis(train_0,shop_supercategory_encoding,shop_supercategory_encoding_seniority_0,'shop_supercategory',['month_id','shop_id','item_supercategory_id'],0)
 compare_features(shop_supercategory_encoding,shop_supercategory_encoding_seniority_0,'shop_supercategory',['month_id','shop_id','item_supercategory_id'],0,20,20,20 )<create_dataframe>
folds = StratifiedKFold(n_splits=10, shuffle=True, random_state=31415)
 oof = np.zeros(len(train))
predictions = np.zeros(len(test))
feature_importance_df = pd.DataFrame()
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train.values, target.values)) :
print("Fold {}".format(fold_))
trn_data = lgb.Dataset(train.iloc[trn_idx][features], label=target.iloc[trn_idx])
 val_data = lgb.Dataset(train.iloc[val_idx][features], label=target.iloc[val_idx])
 num_round = 15000
clf = lgb.train(param, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=1000, early_stopping_rounds = 200)
 oof[val_idx] = clf.predict(train.iloc[val_idx][features], num_iteration=clf.best_iteration)
 fold_importance_df = pd.DataFrame()
fold_importance_df["Feature"] = features
fold_importance_df["importance"] = clf.feature_importance()
fold_importance_df["fold"] = fold_ + 1
feature_importance_df = pd.concat([feature_importance_df, fold_importance_df], axis=0)
 predictions += clf.predict(test[features], num_iteration=clf.best_iteration)/ folds.n_splits
print("CV score: {:<8.5f}".format(roc_auc_score(target, oof)) )
ts = time.time()
target_features_df=[]
col_labels=['shop_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(moving_statistics(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,34,'mean',suffix='_absolute_mean'))
target_features_df.append(moving_statistics(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,12,'mean',suffix='_annual_mean'))
target_features_df.append(moving_statistics(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,6,'mean',suffix='_semiannual_mean'))
target_features_df.append(moving_statistics(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,[1]))
target_features_df.append(lag_features(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,[12]))
print('time : ' +str(time.time() - ts))
col_labels=['supercategory_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(moving_statistics(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,34,'mean',suffix='_absolute_mean'))
target_features_df.append(moving_statistics(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,12,'mean',suffix='_annual_mean'))
target_features_df.append(moving_statistics(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,6,'mean',suffix='_semiannual_mean'))
target_features_df.append(moving_statistics(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,[1]))
target_features_df.append(lag_features(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,[12]))
print('time : ' +str(time.time() - ts))
col_labels=['shop_supercategory_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding_seniority_0,['month_id','shop_id','item_supercategory_id'],col_labels_seniority_0,34,'mean',suffix='_absolute_mean'))
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding_seniority_0,['month_id','shop_id','item_supercategory_id'],col_labels_seniority_0,12,'mean',suffix='_annual_mean'))
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding_seniority_0,['month_id','shop_id','item_supercategory_id'],col_labels_seniority_0,6,'mean',suffix='_semiannual_mean'))
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding_seniority_0,['month_id','shop_id','item_supercategory_id'],col_labels_seniority_0,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,shop_supercategory_encoding_seniority_0,['month_id','shop_id','item_supercategory_id'],col_labels_seniority_0,[1]))
target_features_df.append(lag_features(train_0,shop_supercategory_encoding_seniority_0,['month_id','shop_id','item_supercategory_id'],col_labels_seniority_0,[12]))
print('time : ' +str(time.time() - ts))
col_labels=['category_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(moving_statistics(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,34,'mean',suffix='_absolute_mean'))
target_features_df.append(moving_statistics(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,12,'mean',suffix='_annual_mean'))
target_features_df.append(moving_statistics(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,6,'mean',suffix='_semiannual_mean'))
target_features_df.append(moving_statistics(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,[1]))
target_features_df.append(lag_features(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,[12]))
print('time : ' +str(time.time() - ts))
col_labels=['shop_category_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(moving_statistics(train_0,shop_category_encoding_seniority_0,['month_id','shop_id','item_category_id'],col_labels_seniority_0,34,'mean',suffix='_absolute_mean'))
target_features_df.append(moving_statistics(train_0,shop_category_encoding_seniority_0,['month_id','shop_id','item_category_id'],col_labels_seniority_0,12,'mean',suffix='_annual_mean'))
target_features_df.append(moving_statistics(train_0,shop_category_encoding_seniority_0,['month_id','shop_id','item_category_id'],col_labels_seniority_0,6,'mean',suffix='_semiannual_mean'))
target_features_df.append(moving_statistics(train_0,shop_category_encoding_seniority_0,['month_id','shop_id','item_category_id'],col_labels_seniority_0,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,shop_category_encoding_seniority_0,['month_id','shop_id','item_category_id'],col_labels_seniority_0,[1]))
target_features_df.append(lag_features(train_0,shop_category_encoding_seniority_0,['month_id','shop_id','item_category_id'],col_labels_seniority_0,[12]))
print('time : ' +str(time.time() - ts))
col_labels=['shop_category_avg_sales_compared_to_category']
target_features_df.append(moving_statistics(train_0,shop_category_encoding,['month_id','shop_id','item_category_id'],col_labels,34,'mean',suffix='_absolute_mean'))
target_features_df.append(moving_statistics(train_0,shop_category_encoding,['month_id','shop_id','item_category_id'],col_labels,12,'mean',suffix='_annual_mean'))
target_features_df.append(moving_statistics(train_0,shop_category_encoding,['month_id','shop_id','item_category_id'],col_labels,6,'mean',suffix='_semiannual_mean'))
target_features_df.append(moving_statistics(train_0,shop_category_encoding,['month_id','shop_id','item_category_id'],col_labels,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,shop_category_encoding,['month_id','shop_id','item_category_id'],col_labels,[1]))
target_features_df.append(lag_features(train_0,shop_category_encoding,['month_id','shop_id','item_category_id'],col_labels,[12]))
col_labels=['shop_supercategory_avg_sales_compared_to_supercategory']
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding,['month_id','shop_id','item_supercategory_id'],col_labels,34,'mean',suffix='_absolute_mean'))
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding,['month_id','shop_id','item_supercategory_id'],col_labels,12,'mean',suffix='_annual_mean'))
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding,['month_id','shop_id','item_supercategory_id'],col_labels,6,'mean',suffix='_semiannual_mean'))
target_features_df.append(moving_statistics(train_0,shop_supercategory_encoding,['month_id','shop_id','item_supercategory_id'],col_labels,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,shop_supercategory_encoding,['month_id','shop_id','item_supercategory_id'],col_labels,[1]))
target_features_df.append(lag_features(train_0,shop_supercategory_encoding,['month_id','shop_id','item_supercategory_id'],col_labels,[12]))
print('time : ' +str(time.time() - ts))
col_labels=['shop_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(rational_fraction(train_0,shop_encoding,['month_id','shop_id'],col_labels,weights_num=[0,0,0,0,0,0,0,0,0,0,0,12],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag12_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,shop_encoding,['month_id','shop_id'],col_labels,weights_num=[12,0,0,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag1_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,shop_encoding,['month_id','shop_id'],col_labels,weights_num=[4,4,4,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_recent_mean_to_annual_mean'))
col_labels=['category_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(rational_fraction(train_0,category_encoding,['month_id','item_category_id'],['category_avg_sales'],weights_num=[0,0,0,0,0,0,0,0,0,0,0,12],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag12_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,category_encoding,['month_id','item_category_id'],['category_avg_sales'],weights_num=[12,0,0,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag1_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,category_encoding,['month_id','item_category_id'],['category_avg_sales'],weights_num=[4,4,4,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_recent_mean_to_annual_mean'))
col_labels=['supercategory_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(rational_fraction(train_0,supercategory_encoding,['month_id','item_supercategory_id'],col_labels,weights_num=[0,0,0,0,0,0,0,0,0,0,0,12],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag12_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,supercategory_encoding,['month_id','item_supercategory_id'],col_labels,weights_num=[12,0,0,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag1_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,supercategory_encoding,['month_id','item_supercategory_id'],col_labels,weights_num=[4,4,4,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_recent_mean_to_annual_mean'))
col_labels=['category_avg_sales_compared_to_supercategory']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(moving_statistics(train_0,category_encoding,['month_id','item_category_id'],col_labels,3,'mean',suffix='_recent_mean'))
target_features_df.append(lag_features(train_0,category_encoding,['month_id','item_category_id'],col_labels,[1]))
target_features_df.append(lag_features(train_0,category_encoding,['month_id','item_category_id'],col_labels,[12]))
print('time : ' +str(time.time() - ts))
col_labels=['shop_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(rational_fraction(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,weights_num=[0,0,0,0,0,0,0,0,0,0,0,12],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag12_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,weights_num=[12,0,0,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag1_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,shop_encoding_seniority_0,['month_id','shop_id'],col_labels_seniority_0,weights_num=[4,4,4,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_recent_mean_to_annual_mean'))
col_labels=['supercategory_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(rational_fraction(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,weights_num=[0,0,0,0,0,0,0,0,0,0,0,12],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag12_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,weights_num=[12,0,0,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag1_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,supercategory_encoding_seniority_0,['month_id','item_supercategory_id'],col_labels_seniority_0,weights_num=[4,4,4,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_recent_mean_to_annual_mean'))
col_labels=['category_avg_sales']
col_labels_seniority_0=[col+'_seniority_0' for col in col_labels]
target_features_df.append(rational_fraction(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,weights_num=[0,0,0,0,0,0,0,0,0,0,0,12],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag12_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,weights_num=[12,0,0,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_lag1_to_annual_mean'))
target_features_df.append(rational_fraction(train_0,category_encoding_seniority_0,['month_id','item_category_id'],col_labels_seniority_0,weights_num=[4,4,4,0,0,0,0,0,0,0,0,0],weights_denom=[1,1,1,1,1,1,1,1,1,1,1,1],suffix='_compare_recent_mean_to_annual_mean'))
print('time : ' +str(time.time() - ts))
train_0=pd.concat([train_0]+target_features_df,axis=1,sort=False)
 del target_features_df
gc.collect()
print('time : ' +str(time.time() - ts))
print(train_0.info(null_counts=True,verbose=True))
train_0<drop_column>
sub_df = pd.DataFrame({"ID_code":test["ID_code"].values})
 sub_df["target"] = predictions
sub_df.to_csv("submission.csv", index=False )
for df in dfs:
exec("del "+df)
 exec("del "+df+"_seniority_0")
 gc.collect()<drop_column>
model = CatBoostClassifier(loss_function="Logloss", eval_metric="AUC")
 kf = KFold(n_splits=10, random_state=42, shuffle=True)
 y_valid_pred = 0 * target
y_test_pred = 0
for idx,(train_index, valid_index)in enumerate(kf.split(train)) :
y_train, y_valid = target.iloc[train_index], target.iloc[valid_index]
X_train, X_valid = train[features].iloc[train_index,:], train[features].iloc[valid_index,:]
_train = Pool(X_train, label=y_train)
 _valid = Pool(X_valid, label=y_valid)
 print("
Fold ", idx)
 fit_model = model.fit(_train,
eval_set=_valid,
use_best_model=True,
verbose=200 
)
 pred = fit_model.predict_proba(X_valid)[:,1]
print(" auc = ", roc_auc_score(y_valid, pred))
y_valid_pred.iloc[valid_index] = pred
y_test_pred += fit_model.predict_proba(test[features])[:,1]
y_test_pred /= 5
train_0.drop(features_to_discard,axis=1,inplace=True)
 train_0.info(null_counts=True,verbose=True )<load_pretrained>
sub_df1 = pd.DataFrame({"ID_code":test["ID_code"].values})
 sub_df1["target"] = y_test_pred
sub_df1.to_csv("cat_submission.csv", index=False )
create_directory(os.path.join(DATA_FOLDER, 'training'))
train_0.to_pickle(os.path.join(DATA_FOLDER,'training/train_0_pred.pkl'))<set_options>
sub_df2 = pd.DataFrame({"ID_code":test["ID_code"].values})
 sub_df2["target"] = 0.5*sub_df["target"] + 0.5*sub_df1["target"]
sub_df2.to_csv("lgb_cat_submission.csv", index=False )