Kaggle competition: Santander Customer Transaction Prediction
<SOS> metric: AUC Kaggle data source: santander-customer-transaction-prediction<define_variables>
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
categorical_features = ['item_category_id',
'item_subcategory',
'item_category',
'shop_type',
'city',
'shop_id']<split>
df = pd.read_csv('.. /input/train.csv',index_col='ID_code')
 df.head()
kf = KFold(n_splits = 5, random_state=42)
 resu1 = 0
impor1 = 0
resu3_mae=0
y_pred = 0
y_final_test = 0
stack_train = np.zeros([X_train.shape[0], ])
 models = []
for train_index, test_index in tqdm(list(kf.split(X_train, y_train))):
X_train2 = X_train.iloc[train_index, :]
y_train2 = y_train.iloc[train_index]
X_test2 = X_train.iloc[test_index, :]
y_test2 = y_train.iloc[test_index]
d_training = lgb.Dataset(X_train2, label=y_train2,
categorical_feature=categorical_features,
free_raw_data=False)
 d_test = lgb.Dataset(X_test2, label=y_test2,
categorical_feature=categorical_features,
free_raw_data=False)
 clf = lgb.train(params, train_set=d_training, num_boost_round=1000,
valid_sets=[d_training, d_test], verbose_eval=25,
early_stopping_rounds=50)
 models.append(clf)
 temp_predict = clf.predict(X_test2, num_iteration=clf.best_iteration)
 stack_train[test_index] = temp_predict
y_pred += clf.predict(X_test, num_iteration=clf.best_iteration)/5
y_final_test += clf.predict(X_final_test, num_iteration=clf.best_iteration)/5
mse = mean_squared_error(y_test2, temp_predict)
 mae = mean_absolute_error(y_test2, temp_predict)
 resu1 += mse/5
resu3_mae += mae/5
impor1 += clf.feature_importance() /5
del X_train2, y_train2, X_test2, y_test2; gc.collect()<save_to_csv>
y = df['target']
X = df.drop('target',axis=1)
 test = pd.read_csv('.. /input/test.csv',index_col='ID_code' )
submission = pd.DataFrame({
"ID": test_df.index,
"item_cnt_month": y_final_test
})
 submission.to_csv('submission_no_features.csv', index=False )<import_modules>
import lightgbm as lgb
from sklearn.model_selection import KFold
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from time import time
import gc
from xgboost import XGBRegressor<define_variables>
n_splits = 5
kf = KFold(n_splits=n_splits)
 warnings.filterwarnings('ignore')
 param = {'objective': 'binary', 'metric': 'auc', 'learning_rate': 0.0122, 'num_rounds': 7000, 'verbose': 1, 'n_estimators':500}
test_pred = np.zeros(len(test))
for fold,(train_indx, val_indx)in enumerate(kf.split(y)) :
print("Fold {}".format(fold+1))
train_set = lgb.Dataset(X.iloc[train_indx], label=y.iloc[train_indx])
 val_set = lgb.Dataset(X.iloc[val_indx], label=y.iloc[val_indx])
 model = lgb.train(param, train_set, valid_sets=val_set, verbose_eval=500)
 test_pred += model.predict(test)/n_splits
LOCATION_KAGGLE = True
SHOW_EDA = True
DOWNSEL_14MONS = False
DOWNSEL_26MONS = True
SHIFT_1MONTH = False
DOWNSEL_OUT = True
USE_CNT_CLIP = False<define_variables>
submission = pd.read_csv('.. /input/sample_submission.csv')
 sub = pd.DataFrame(test_pred,columns=['target'])
 submission.update(sub )
RANDOM_SEED = 730
np.random.seed(RANDOM_SEED)
 print(RANDOM_SEED )<define_variables>
submission.to_csv('lightgbm2.csv',index=False )