Kaggle competition: Santander Customer Transaction Prediction
<SOS> metric: AUC Kaggle data source: santander-customer-transaction-prediction<define_variables>
print(os.listdir(".. /input"))
null_columns = [index for index,value in null_check.items() if value >= train_data.shape[0]*0.8]<define_variables>
test_data = pd.read_csv(".. /input/test.csv")
 train_data= pd.read_csv(".. /input/train.csv")
 train_data.head()
catagorical_variables = [index for index, value in train_data.dtypes.items() if value == "object"]<define_variables>
count_0 = len(train_data[train_data["target"] == 0])
 count_1 = len(train_data[train_data["target"] == 1])
 percentage_count_0 =(( count_0)/(count_0+count_1)) * 100
percentage_count_1 = 100-percentage_count_0
print("{}{}{}{}{}".format("Percentage of 0 class is ",percentage_count_0,"
","Percentage of 1 class is ",percentage_count_1))
catagorical_variables = [var for var in catagorical_variables if var not in null_columns and var not in low_correlation]<concatenate>
labels = train_data["target"]
new_train_data = train_data.drop(["target","ID_code"],axis =1)
 new_train_data.head()
x_train, x_test, y_train, y_test = train_test_split(new_train_data, labels, test_size = 0.25, random_state = 0)
 print(x_train.shape,x_test.shape)
 print(y_train.shape,y_test.shape)
 x_train.head()
combined_data = pd.concat([train_data,test_data] )<choose_model_class>
folds = StratifiedKFold(n_splits=10, shuffle=False, random_state=2319)
 param = {
'bagging_freq': 5,
'bagging_fraction': 0.33,
'boost_from_average':'false',
'boost': 'gbdt',
'feature_fraction': 0.0405,
'learning_rate': 0.083,
'max_depth': -1,
'metric':'auc',
'min_data_in_leaf': 80,
'min_sum_hessian_in_leaf': 10.0,
'num_leaves': 13,
'num_threads': 4,
'tree_learner': 'serial',
'objective': 'binary',
'verbosity': 1
}
oof = np.zeros(len(train_data))
predictions = np.zeros(len(test_data))
features = [c for c in train_data.columns if c not in ['ID_code', 'target']]
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train_data.values, labels.values)) :
trn_data = lgb.Dataset(train_data.iloc[trn_idx][features], label=labels.iloc[trn_idx])
 val_data = lgb.Dataset(train_data.iloc[val_idx][features], label=labels.iloc[val_idx])
 clf = lgb.train(param, trn_data, 1000, valid_sets = [trn_data, val_data], verbose_eval=5000, early_stopping_rounds = 4000)
 oof[val_idx] = clf.predict(train_data.iloc[val_idx][features], num_iteration=clf.best_iteration)
 predictions += clf.predict(test_data[features], num_iteration=clf.best_iteration)/ folds.n_splits
modal_imputer = SimpleImputer(missing_values=np.nan, strategy='most_frequent')
 mean_imputer = SimpleImputer(missing_values=np.nan, strategy='mean' )<categorify>
target = train_data.iloc[val_idx]['target']
print("
>> CV score: {:<8.5f}".format(roc_auc_score(target, oof[val_idx])))
<categorify><EOS> 
ID_code = test_data["ID_code"]
submission = pd.DataFrame({'ID_code' : ID_code,
'target' : predictions})
 submission.to_csv('./version1.csv', index=False)
 sub = pd.read_csv('./version1.csv')
 sub.head()