Kaggle competition: Home Credit Default Risk
sub = pd.DataFrame({'Id': test.Id, 'SalePrice': preds})
 sub.to_csv('submission.csv', index=False )<set_options>
%matplotlib inline
warnings.filterwarnings('ignore')
<load_from_csv>
from sklearn.model_selection import GridSearchCV
from skopt import BayesSearchCV
data_path = '.. /input/kaggledays-paris/'
train = pd.read_csv(data_path + 'train.csv',encoding='UTF-8')
 test = pd.read_csv(data_path + 'test.csv',encoding='UTF-8')
 colorfile = pd.read_csv('.. /input/color-feature/color_transcode2.csv',encoding='UTF-8')
 train = train.merge(colorfile, on='color', how='left')
 test = test.merge(colorfile, on='color', how='left')
 train['color'] = train['new_color']
test['color'] = test['new_color']
print(train.shape, test.shape)
 print(train.head())
 train['is_test'] = 0
test['is_test'] = 1
df_all = pd.concat([train, test], axis=0)
 print('train ',train.shape)
 print('test ',test.shape )<categorify>
import lightgbm as lgb
print('Preprocessing text...')
 tfidf = TfidfVectorizer(max_features=5,norm='l2',)
 tfidf.fit(df_all[ 'en_US_description'].astype(str ).values)
 tfidf_all = np.array(tfidf.transform(df_all[ 'en_US_description'].astype(str ).values ).toarray() , dtype=np.float16)
 for i in tqdm(range(5)) :
df_all['en_US_description_tfidf_' + str(i)] = tfidf_all[:, i]
del tfidf, tfidf_all
gc.collect()
print('Done.')
 print('train ',train.shape)
 print('test ',test.shape )<categorify>
import gc
print('Label Encoder...')
 cols = [f_ for f_ in df_all.columns if df_all[f_].dtype == 'object' and 'sku' not in f_ and 'ID' not in f_]
print(cols)
 cnt = 0
for c in tqdm(cols):
le = LabelEncoder()
df_all[c] = le.fit_transform(df_all[c].astype(str))
cnt += 1
del le
print('len(cols)= {}'.format(cnt))
train = df_all.loc[df_all['is_test'] == 0].drop(['is_test'], axis=1)
 test = df_all.loc[df_all['is_test'] == 1].drop(['is_test'], axis=1)
 print('train ',train.shape)
 print('test ',test.shape )<merge>
from sklearn.model_selection import train_test_split, KFold, StratifiedKFold
from sklearn.metrics import accuracy_score, confusion_matrix
from sklearn.feature_selection import VarianceThreshold
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, MinMaxScaler
vimages = pd.read_csv(data_path + 'vimages.csv')
 pca = PCA(n_components=10)
 vpca = pca.fit_transform(vimages.drop('sku_hash', axis=1 ).values)
 vimages_pca = vimages[['sku_hash']]
for i in tqdm(range(vpca.shape[1])) :
vimages_pca['dim_pca_{}'.format(i)] = vpca[:, i]
train = train.merge(vimages_pca, on='sku_hash', how='left')
 test = test.merge(vimages_pca, on='sku_hash', how='left')
 print('train ',train.shape)
 print('test ',test.shape )<merge>
def status_print(optim_result):

 all_models = pd.DataFrame(bayes_cv_tuner.cv_results_)
 best_params = pd.Series(bayes_cv_tuner.best_params_)
 print('Model
Best ROC-AUC: {}
Best params: {}
'.format(
 len(all_models),
np.round(bayes_cv_tuner.best_score_, 4),
bayes_cv_tuner.best_params_ 
))
clf_name = bayes_cv_tuner.estimator.__class__.__name__
all_models.to_csv(clf_name+"_cv_results.csv" )
sales = pd.read_csv(data_path + 'sales.csv')
 sales = sales.merge(df_all[['sku_hash','model','function']], on='sku_hash', how='left')
 sales = sales.sort_values('Date', ascending=True)
 salesg = sales.groupby('sku_hash' ).agg({
'sales_quantity': ['sum', 'mean'],
'Month_transaction': ['last'],
} ).reset_index()
salesg.columns = ['%s%s' %(a, '_%s' % b if b else '')for a, b in salesg.columns]
print(salesg.head())
 train = train.merge(salesg, on='sku_hash', how='left')
 test = test.merge(salesg, on='sku_hash', how='left')
 aggs={}
aggs['sales_quantity']= {'sum':'sum'}
agg_tmp = sales.groupby(['sku_hash','Date'] ).agg(aggs)
 agg_tmp.columns = [ '{}_{}'.format(k, agg)for k in aggs.keys() for agg in aggs[k]]
agg_tmp=agg_tmp.reset_index()
agg_tmp = agg_tmp.sort_values('Date', ascending=True)
 XX_sales = agg_tmp.groupby(['sku_hash'])['sales_quantity_sum'].apply(lambda x: sales_features(x))
XX_sales = expand_series_to_df(XX_sales.reset_index())
 XX_sales.columns = ['sku_hash',
'sales_quantity_sum_linear_trend_rvalue',
'sales_quantity_sum_linear_trend_intercept',
'sales_quantity_sum_linear_trend_attr_slope',
'sales_quantity_sum_linear_trend_attr_stderr',
'sales_quantity_sum_kurtosis',
'sales_quantity_sum_skewness'
]
train = train.merge(XX_sales, on='sku_hash', how='left')
 test = test.merge(XX_sales, on='sku_hash', how='left')
 print('train ',train.shape)
 print('test ',test.shape )<groupby>
data = pd.read_csv(".. /input/application_train.csv")
 test = pd.read_csv('.. /input/application_test.csv')
 prev = pd.read_csv('.. /input/previous_application.csv')
 buro = pd.read_csv('.. /input/bureau.csv')
 buro_balance = pd.read_csv('.. /input/bureau_balance.csv')
 credit_card = pd.read_csv('.. /input/credit_card_balance.csv')
 POS_CASH = pd.read_csv('.. /input/POS_CASH_balance.csv')
 payments = pd.read_csv('.. /input/installments_payments.csv')
 lgbm_submission = pd.read_csv('.. /input/sample_submission.csv' )
agg_tmp = sales.groupby(['model','Date'] ).agg(aggs)
 agg_tmp.columns = [ '{}_{}'.format(k, agg)for k in aggs.keys() for agg in aggs[k]]
agg_tmp=agg_tmp.reset_index()
agg_tmp = agg_tmp.sort_values('Date', ascending=True)
 XX_sales_BYMODEL = agg_tmp.groupby(['model'])['sales_quantity_sum'].apply(lambda x: sales_features(x))
XX_sales_BYMODEL = expand_series_to_df(XX_sales_BYMODEL.reset_index())
 XX_sales_BYMODEL.columns = ['model',
'BYMODELsales_quantity_sum_linear_trend_rvalue',
'BYMODELsales_quantity_sum_linear_trend_intercept',
'BYMODELsales_quantity_sum_linear_trend_attr_slope',
'BYMODELsales_quantity_sum_linear_trend_attr_stderr',
'BYMODELsales_quantity_sum_kurtosis',
'BYMODELsales_quantity_sum_skewness'
]
train = train.merge(XX_sales_BYMODEL, on='model', how='left')
 test = test.merge(XX_sales_BYMODEL, on='model', how='left')
 print('train ',train.shape)
 print('test ',test.shape )<feature_engineering>
y = data["TARGET"]
del data["TARGET"]
def extract_features(df):
df['month_real'] =(df['month']+df['Month_transaction_last'] ).apply(lambda x: x%12)
 pass
print('Extracting month_real features for train:')
 extract_features(train)
 print('Extracting month_real features for test:')
 extract_features(test)
 print('train ',train.shape)
 print('test ',test.shape )<prepare_x_and_y>
categorical_feature = [col for col in data.columns if data[col].dtype == 'object']
y = np.log1p(train['target'].values)
 f = [
'en_US_description_tfidf_0', 'en_US_description_tfidf_1', 'en_US_description_tfidf_2', 'en_US_description_tfidf_3', 'en_US_description_tfidf_4',
'dim_pca_0', 'dim_pca_1', 'dim_pca_2', 'dim_pca_3','dim_pca_4',
'dim_pca_5', 'dim_pca_6', 'dim_pca_7', 'dim_pca_8','dim_pca_9',
'sales_quantity_sum',
'sales_quantity_mean',
'fr_FR_price',
'product_type',
'month',
'month_real',
'product_gender',
'macro_function',
'function',
'macro_material',
'color',
'Month_transaction_last',
'sales_quantity_sum_linear_trend_rvalue',
'sales_quantity_sum_linear_trend_intercept',
'sales_quantity_sum_linear_trend_attr_slope',
'sales_quantity_sum_linear_trend_attr_stderr',
'sales_quantity_sum_kurtosis',
'sales_quantity_sum_skewness',
'BYMODELsales_quantity_sum_linear_trend_rvalue',
'BYMODELsales_quantity_sum_linear_trend_intercept',
'BYMODELsales_quantity_sum_linear_trend_attr_slope',
'BYMODELsales_quantity_sum_linear_trend_attr_stderr',
'BYMODELsales_quantity_sum_kurtosis',
'BYMODELsales_quantity_sum_skewness',
]<features_selection>
one_hot_df = pd.concat([data, test])
 one_hot_df = pd.get_dummies(one_hot_df, columns=categorical_feature )
clfs, importances, err, oof_predict = train_classifiers(train,y,f)
<save_to_csv>
data = one_hot_df.iloc[:data.shape[0],:]
test = one_hot_df.iloc[data.shape[0]:,]
preds_ = None
for clf in clfs:
if preds_ is None:
preds_ = clf.predict(test[f], num_iteration=clf.best_iteration_)
 else:
preds_ += clf.predict(test[f], num_iteration=clf.best_iteration_)
 preds_ = preds_ / len(clfs)
 preds_ = np.expm1(preds_)
 subm = pd.DataFrame()
subm['ID'] = test['ID'].values
subm['target'] = preds_
subm.to_csv('submission{}.csv'.format(err), index=False)
<import_modules>
buro_grouped_size = buro_balance.groupby("SK_ID_BUREAU")["MONTHS_BALANCE"].size()
buro_grouped_max = buro_balance.groupby("SK_ID_BUREAU")["MONTHS_BALANCE"].max()
buro_grouped_min = buro_balance.groupby("SK_ID_BUREAU")["MONTHS_BALANCE"].min()
import torch
import torch.nn as nn
import pandas as pd
import numpy as np
import xgboost as xgb
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.model_selection import TimeSeriesSplit,KFold, StratifiedKFold
from time import time
import pickle
import datetime as dt
from imblearn.over_sampling import RandomOverSampler
from scipy.sparse import csc_matrix<import_modules>
buro_counts = buro_balance.groupby("SK_ID_BUREAU")["STATUS"].value_counts(normalize=False)
 buro_counts_unstacked = buro_counts.unstack("STATUS")
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader, random_split<load_from_csv>
buro_counts_unstacked.columns = ['STATUS_0', 'STATUS_1','STATUS_2','STATUS_3','STATUS_4','STATUS_5','STATUS_C','STATUS_X',]
buro_counts_unstacked["MONTHS_COUNT"] = buro_grouped_size
buro_counts_unstacked["MONTHS_MIN"] = buro_grouped_min
buro_counts_unstacked["MONTHS_MAX"] = buro_grouped_max
def init_read_big(train_path, test_path, train_big_path):
train = pd.read_csv(train_path)
 test = pd.read_csv(test_path)
 train_big = pd.read_csv(train_big_path)
 return train, test, train_big
def init_read_small(train_path, test_path):
train = pd.read_csv(train_path)
 test = pd.read_csv(test_path)
 return train, test
def remove_column_big(train, train_big, column_title_big):
train_small = train.copy()
column_title_small = [A for A in train.columns]
train_big = train_big[column_title_big]
train = train_big.copy()
train.columns = column_title_small
return train
def data_preprocessing(train, test):
train = train.drop(['Quote_ID'], axis=1)
 y = train.QuoteConversion_Flag.values
train = train.drop(['QuoteConversion_Flag'], axis=1)
 test = test.drop('Quote_ID', axis=1)
 train['Date'] = pd.to_datetime(pd.Series(train['Original_Quote_Date']))
train = train.drop('Original_Quote_Date', axis=1)
 test['Date'] = pd.to_datetime(pd.Series(test['Original_Quote_Date']))
test = test.drop('Original_Quote_Date', axis=1)
 train['Year'] = train['Date'].apply(lambda x: int(str(x)[:4]))
train['Month'] = train['Date'].apply(lambda x: int(str(x)[5:7]))
train['weekday'] = train['Date'].dt.dayofweek
test['Year'] = test['Date'].apply(lambda x: int(str(x)[:4]))
test['Month'] = test['Date'].apply(lambda x: int(str(x)[5:7]))
test['weekday'] = test['Date'].dt.dayofweek
train = train.drop(['Date'], axis=1)
 test = test.drop(['Date'], axis=1)

for A in train.columns:
if train[A].dtype=='object':
lbl = preprocessing.LabelEncoder()
lbl.fit(list(train[A].values)+ list(test[A].values))
train[A] = lbl.transform(list(train[A].values))
test[A] = lbl.transform(list(test[A].values))
train = train.fillna(-999)
 test = test.fillna(-999)
 print("
Pre-processing_big complete!!")
 return train, test, y 
<load_from_csv>
buro = buro.join(buro_counts_unstacked, how='left', on='SK_ID_BUREAU' )
train_path = '/kaggle/input/2019s-uts-data-analytics-assignment-3/Assignment3_TrainingSet.csv'
test_path = '/kaggle/input/2019s-uts-data-analytics-assignment-3/Assignment3_TestSet.csv'
train, test = init_read_small(train_path, test_path)
 train, test, y = data_preprocessing(train, test )<normalization>
prev_cat_features = [pcol for pcol in prev.columns if prev[pcol].dtype == "object"]
prev = pd.get_dummies(prev, columns=prev_cat_features)
sc = StandardScaler()
train = sc.fit_transform(train)
 test = sc.fit_transform(test )<train_model>
avg_prev = prev.groupby("SK_ID_CURR" ).mean()
<normalization>
cnt_prev = prev[["SK_ID_CURR", "SK_ID_PREV"]].groupby("SK_ID_CURR" ).count()
avg_prev["nb_app"] = cnt_prev["SK_ID_PREV"]
del avg_prev["SK_ID_PREV"]
class Net(nn.Module):
def __init__(self, D_in, H=15, D_out=1):
super().__init__()
self.fc1 = nn.Linear(D_in, H)
 self.fc2 = nn.Linear(H, D_out)
 self.relu = nn.ReLU()
def forward(self, x):
x = self.fc1(x)
 x = self.relu(x)
 x = self.fc2(x)
 return x.squeeze()<find_best_params>
buro_cat_features = [bcol for bcol in buro.columns if buro[bcol].dtype == 'object']
buro = pd.get_dummies(buro, columns=buro_cat_features)
 avg_buro = buro.groupby('SK_ID_CURR' ).mean()
avg_buro['buro_count'] = buro[['SK_ID_BUREAU', 'SK_ID_CURR']].groupby('SK_ID_CURR' ).count() ['SK_ID_BUREAU']
del avg_buro['SK_ID_BUREAU']
class EarlyStopping(object):
def __init__(self, mode='min', min_delta=0, patience=10, percentage=False):
self.mode = mode
self.min_delta = min_delta
self.patience = patience
self.best = None
self.num_bad_epochs = 0
self.is_better = None
self._init_is_better(mode, min_delta, percentage)
 if patience == 0:
self.is_better = lambda a, b: True
self.step = lambda a: False
def step(self, metrics):
if self.best is None:
self.best = metrics
return False
if np.isnan(metrics):
return True
if self.is_better(metrics, self.best):
self.num_bad_epochs = 0
self.best = metrics
else:
self.num_bad_epochs += 1
if self.num_bad_epochs >= self.patience:
return True
return False
def _init_is_better(self, mode, min_delta, percentage):
if mode not in {'min', 'max'}:
raise ValueError('mode ' + mode + ' is unknown!')
 if not percentage:
if mode == 'min':
self.is_better = lambda a, best: a < best - min_delta
if mode == 'max':
self.is_better = lambda a, best: a > best + min_delta
else:
if mode == 'min':
self.is_better = lambda a, best: a < best -(
 best * min_delta / 100)
 if mode == 'max':
self.is_better = lambda a, best: a > best +(
 best * min_delta / 100 )<set_options>
le = LabelEncoder()
POS_CASH['NAME_CONTRACT_STATUS'] = le.fit_transform(POS_CASH['NAME_CONTRACT_STATUS'].astype(str))
nunique_status = POS_CASH[['SK_ID_CURR', 'NAME_CONTRACT_STATUS']].groupby('SK_ID_CURR' ).nunique()
nunique_status2 = POS_CASH[['SK_ID_CURR', 'NAME_CONTRACT_STATUS']].groupby('SK_ID_CURR' ).max()
nunique_status2.head(10 )
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu" )<split>
POS_CASH['NUNIQUE_STATUS'] = nunique_status['NAME_CONTRACT_STATUS']
POS_CASH['NUNIQUE_STATUS2'] = nunique_status2['NAME_CONTRACT_STATUS']
POS_CASH.drop(['SK_ID_PREV', 'NAME_CONTRACT_STATUS'], axis=1, inplace=True )
n_fold = 5
random_state = 999
D_in, H = 30, 15
models = []
train_no = 1
training_cycle = 20000
repetition = 1
training_sequence = 1
for A in range(repetition):
kf = StratifiedKFold(n_splits = n_fold , shuffle = True, random_state = random_state+A)
 for train_index, val_index in kf.split(train, y):
train_X = train[train_index]
val_X = train[val_index]
train_y = y[train_index]
val_y = y[val_index]
train_X_torch = torch.tensor(train_X)
 val_X_torch = torch.tensor(val_X)
 train_y_torch = torch.tensor(train_y)
 val_y_torch = torch.tensor(val_y)
 print(f'
urrently Training sequence no {training_sequence}')
 net = Net(D_in, H ).to(device)
 criteria = nn.MSELoss()
optimizer = optim.Adam(net.parameters() , weight_decay=0.0001)
 es = EarlyStopping(patience=20)
 for epoch in range(training_cycle):
print(f'Training Epoch No {epoch}')
 inputs = train_X_torch.to(device)
 labels = train_y_torch.to(device)
 inputs_valid = val_X_torch.to(device)
 labels_valid = val_y_torch.to(device)
 optimizer.zero_grad()
outputs = net(inputs.float())
 outputs_valid = net(inputs_valid.float())
 loss = criteria(outputs, labels.float())
 loss_valid = criteria(outputs_valid, labels_valid.float())
 metric_valid = loss_valid.detach().numpy()
loss.backward()
optimizer.step()
print(f'Current Loss is {metric_valid}')
 if es.step(metric_valid):
break
models.append(net)
 training_sequence += 1
del net, es, metric_valid 
<choose_model_class>
le =LabelEncoder()
credit_card['NAME_CONTRACT_STATUS'] = le.fit_transform(credit_card['NAME_CONTRACT_STATUS'].astype(str))
nunique_status = credit_card[['SK_ID_CURR', 'NAME_CONTRACT_STATUS']].groupby('SK_ID_CURR' ).nunique()
nunique_status2 = credit_card[['SK_ID_CURR', 'NAME_CONTRACT_STATUS']].groupby('SK_ID_CURR' ).max()
credit_card['NUNIQUE_STATUS'] = nunique_status['NAME_CONTRACT_STATUS']
credit_card['NUNIQUE_STATUS2'] = nunique_status2['NAME_CONTRACT_STATUS']
credit_card.drop(['SK_ID_PREV', 'NAME_CONTRACT_STATUS'], axis=1, inplace=True)
<define_variables>
avg_payments = payments.groupby("SK_ID_CURR" ).mean()
avg_payments2 = payments.groupby("SK_ID_CURR" ).max()
avg_payments3 = payments.groupby("SK_ID_CURR" ).min()
test_torch = torch.tensor(test)
 pred_df = sum([net(test_torch.float())for net in models])/(n_fold*repetition )<predict_on_test>
del avg_payments["SK_ID_PREV"]
test_predict_numpy = pred_df.detach().numpy()<feature_engineering>
data = data.merge(right=avg_prev.reset_index() , how="left", on="SK_ID_CURR")
 test = test.merge(right=avg_prev.reset_index() , how="left", on="SK_ID_CURR")
for A in range(len(test_predict_numpy)) :
if test_predict_numpy[A] > np.mean(test_predict_numpy):
test_predict_numpy[A] = 1
else:
test_predict_numpy[A] = 0<count_values>
data = data.merge(right=avg_buro.reset_index() , how='left', on='SK_ID_CURR')
 test = test.merge(right=avg_buro.reset_index() , how='left', on='SK_ID_CURR' )
sum(test_predict_numpy )<save_to_csv>
data = data.merge(right=POS_CASH.groupby("SK_ID_CURR" ).mean().reset_index() , how="left", on="SK_ID_CURR")
 test = test.merge(right=POS_CASH.groupby("SK_ID_CURR" ).mean().reset_index() , how="left", on="SK_ID_CURR" )
sample = pd.read_csv('/kaggle/input/2019s-uts-data-analytics-assignment-3/Assignment3_Random_Submission-Kaggle.csv')
 sample.QuoteConversion_Flag = test_predict_numpy
sample.to_csv('pytorch_model.csv', index=False)
 print("<load_from_csv>
data = data.merge(credit_card.groupby('SK_ID_CURR' ).mean().reset_index() , how='left', on='SK_ID_CURR')
 test = test.merge(credit_card.groupby('SK_ID_CURR' ).mean().reset_index() , how='left', on='SK_ID_CURR')
train=pd.read_csv('/kaggle/input/ec524-heart-disease/train.csv')
 test=pd.read_csv('/kaggle/input/ec524-heart-disease/test.csv' )<count_missing_values>
data = data.merge(right=avg_payments.reset_index() , how='left', on='SK_ID_CURR')
 test = test.merge(right=avg_payments.reset_index() , how='left', on='SK_ID_CURR')
train.isna().sum()<data_type_conversions>
data = data.merge(right=avg_payments2.reset_index() , how='left', on='SK_ID_CURR')
 test = test.merge(right=avg_payments2.reset_index() , how='left', on='SK_ID_CURR' )
train.fillna(train.mean() ,inplace=True )<count_missing_values>
data = data.merge(right=avg_payments3.reset_index() , how='left', on='SK_ID_CURR')
 test = test.merge(right=avg_payments3.reset_index() , how='left', on='SK_ID_CURR' )
train.isna().sum()<count_missing_values>
test = test[test.columns[data.isnull().mean() < 0.85]]
data = data[data.columns[data.isnull().mean() < 0.85]]
test.isna().sum()<drop_column>
excluded_feats = ["SK_ID_CURR"]
features = [f for f in data.columns if f not in excluded_feats]
train=train.drop(['id'],axis=1 )<prepare_x_and_y>
x=train.drop(['heart_disease'],axis=1)
 y=train['heart_disease'].values<normalization>
lgbm_params = {
"boosting":"dart",
"application":"binary",
"learning_rate": 0.1,
'reg_alpha':0.01,
'reg_lambda': 0.01,
"n_estimators":10000,
"max_depth":7,
"num_leaves":100,
"max_bin":225,
"drop_rate":0.02
}
scaler=StandardScaler()
x=scaler.fit_transform(x)
<choose_model_class>
model = lgb.LGBMClassifier(application="binary", boosting_type=lgbm_params["boosting"],
learning_rate=lgbm_params["learning_rate"],n_estimators=lgbm_params["n_estimators"],drop_rate=lgbm_params["drop_rate"],
num_leaves=lgbm_params["num_leaves"], max_depth=lgbm_params["max_depth"],
max_bin=lgbm_params["max_bin"])
lr=LogisticRegression()
rf=RandomForestClassifier()
vote=VotingClassifier(estimators=[('lr',lr),('rf',rf)] )<train_model>
feature_importances = np.zeros(data.shape[1])
 for i in range(2):
train_data, test_data, train_y, test_y = train_test_split(data, y, test_size=0.2, random_state=i)
 model.fit(train_data, train_y, early_stopping_rounds=100, eval_set=[(test_data, test_y)], eval_metric='auc', verbose=200)
 feature_importances += model.feature_importances_
vote.fit(x,y )<compute_test_metric>
threshold = 0.98
features_to_keep = list(norm_feature_importances[norm_feature_importances['cumulative_importance'] < threshold]['feature'])
 data = data[features_to_keep]
test = test[features_to_keep]
vote.score(x,y )<drop_column>
n_folds = 5
k_fold = KFold(n_splits=n_folds, shuffle=False, random_state=50)
 feature_importances_values = np.zeros(data.shape[1])
 test_predictions = np.zeros(test.shape[0])
 out_of_fold = np.zeros(data.shape[0])
 valid_scores = []
train_scores = []
for train_indices, test_indices in k_fold.split(data):
train_data, train_y = data.iloc[train_indices], y.iloc[train_indices]
test_data, test_y = data.iloc[test_indices], y.iloc[test_indices]
model = lgb.LGBMClassifier(application="binary", boosting_type=lgbm_params["boosting"],
learning_rate=lgbm_params["learning_rate"], n_estimators=lgbm_params["n_estimators"],
num_leaves=lgbm_params["num_leaves"],max_depth=lgbm_params["max_depth"],
reg_lambda=lgbm_params['reg_lambda'],reg_alpha=lgbm_params["reg_alpha"],
drop_rate=lgbm_params["drop_rate"], random_state=50)
 model.fit(train_data, train_y, eval_metric='auc', eval_set=[(test_data, test_y),(train_data, train_y)],
eval_names=['valid', 'train'], early_stopping_rounds=100, verbose=200)
 best_iteration = model.best_iteration_
feature_importances_values += model.feature_importances_ / k_fold.n_splits
test_predictions += model.predict_proba(test, num_iteration=best_iteration)[:,1]/k_fold.n_splits
out_of_fold[test_indices] = model.predict_proba(test_data, num_iteration = best_iteration)[:, 1]
valid_score = model.best_score_['valid']['auc']
train_score = model.best_score_['train']['auc']
valid_scores.append(valid_score)
 train_scores.append(train_score)
 gc.enable()
del model, train_data, test_data
gc.collect()
test_=test.drop(['id'],axis=1 )<normalization>
submission = pd.DataFrame({'SK_ID_CURR': test["SK_ID_CURR"], 'TARGET': test_predictions})
 submission.to_csv("submissions.csv", index=False )