Kaggle competition: Santander Customer Transaction Prediction
<SOS> metric: AUC Kaggle data source: santander-customer-transaction-prediction<count_unique_values>
import lightgbm as lgb
import pandas as pd
import numpy as np
from sklearn.metrics import roc_auc_score
from datetime import datetime
from pathlib import Path
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import RepeatedStratifiedKFold
if SHIFT_1MONTH:
newhot_cats = df_missing.loc[df_missing['newhot'] == 1, 'item_category_id'].unique()
print("Number of new-hot missing categories: {}
".format(len(newhot_cats)))
 for this_cat in newhot_cats:
print(df_categs.loc[this_cat, 'item_category_name'])
<count_unique_values>
path=Path(".. /input/")
 train=pd.read_csv(path/"train.csv" ).drop("ID_code",axis=1)
 test=pd.read_csv(path/"test.csv" ).drop("ID_code",axis=1 )
if SHIFT_1MONTH:
newhot_items = df_missing.loc[df_missing['newhot'] == 1, 'item_id'].unique()
print("Number of new-hot missing items: {}
".format(len(newhot_items)))
 for this_item in newhot_items:
print(df_items.loc[this_item, 'item_name'])
<count_unique_values>
def augment(train,num_n=1,num_p=2):
newtrain=[train]
n=train[train.target==0]
for i in range(num_n):
newtrain.append(n.apply(lambda x:x.values.take(np.random.permutation(len(n)))))
 for i in range(num_p):
p=train[train.target>0]
newtrain.append(p.apply(lambda x:x.values.take(np.random.permutation(len(p)))))
 return pd.concat(newtrain)
if SHIFT_1MONTH:
boring_items = df_missing.loc[(df_missing['boring'] == 1), 'item_id'].unique()
print("Number of boring missing items: {}
".format(len(boring_items)))
<define_variables>
param = {'num_leaves': 16,
'min_data_in_leaf': 42,
'tree_learner': 'serial',
'objective': 'binary',
'max_depth': -1,
'learning_rate': 0.01,
'boosting': 'gbdt',
'bagging_freq': 2,
'bagging_fraction': 0.4,
'feature_fraction': 0.05,
'bagging_seed': 11,
'reg_alpha': 1.728910519108444,
'reg_lambda': 4.9847051755586085,
'random_state': 42,
'metric': 'auc',
'verbosity': -1,
'min_gain_to_split': 7,
'num_threads': -1,
'min_sum_hessian_in_leaf': 10.0,
'boost_from_average':'false'}
EFFNET = 5<import_modules>
result=np.zeros(test.shape[0])
 oof = np.zeros(len(train))
rskf = RepeatedStratifiedKFold(n_splits=5, n_repeats=5,random_state=10)
 for counter,(train_index, valid_index)in enumerate(rskf.split(train, train.target),1):
print(counter)
 t=train.iloc[train_index]
t=augment(t)
 trn_data = lgb.Dataset(t.drop("target",axis=1), label=t.target)
 v=train.iloc[valid_index]
val_data = lgb.Dataset(v.drop("target",axis=1), label=v.target)
 model = lgb.train(param, trn_data, 1000000, valid_sets = [trn_data, val_data], verbose_eval=5000, early_stopping_rounds = 4000)
 result +=model.predict(test, num_iteration=model.best_iteration)
 oof[valid_index]+=model.predict(train.iloc[valid_index], num_iteration=model.best_iteration)
KAGGLE_DIR = '.. /input/aptos2019-blindness-detection/'
TRAIN_DF_PATH = KAGGLE_DIR + "train.csv"
TEST_DF_PATH = KAGGLE_DIR + 'test.csv'
TRAIN_IMG_PATH = KAGGLE_DIR + "train_images/"
TEST_IMG_PATH = KAGGLE_DIR + 'test_images/'
SAVED_MODEL_NAME = 'effnet_b{}_model.h5'.format(EFFNET)
 seed = 1234
rn.seed(seed)
 np.random.seed(seed)
 tf.set_random_seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 t_start = time.time()<install_modules>
score=roc_auc_score(train.target, oof/counter)
 print("CV score: {:<8.8f}".format(score))
!pip install.. /input/efficientnet100
!pip install.. /input/kerasradam/
!pip install.. /input/kerascontrib/
!pip install.. /input/ipythonautotime/
%load_ext autotime<import_modules>
submission = pd.read_csv(path/'sample_submission.csv')
 submission['target'] = result/counter
filename="{:%Y-%m-%d_%H_%M}_sub.csv".format(datetime.now())
 submission.to_csv(filename, index=False )