Kaggle competition: Santander Customer Transaction Prediction
<SOS> metric: AUC Kaggle data source: santander-customer-transaction-prediction<train_on_grid>
%matplotlib inline
print(os.listdir(".. /input"))
lasso = Lasso()
params = {'alpha': [1000, 100, 10, 1, 0.1, 0.01, 0.001]}
cv_l = GridSearchCV(lasso, params, cv = 10, n_jobs =1)
 cv_l.fit(X_train, y_train)
 print("Best params:{}".format(cv_l.best_params_))
best_l = cv_l.best_estimator_
y_train_pred_l = best_l.predict(X_train)
 y_val_pred_l = best_l.predict(X_val)
 print("MSE train:{}".format(mean_squared_error(y_train, y_train_pred_l)))
 print("MSE val;{}".format(mean_squared_error(y_val, y_val_pred_l)))
 print("R2 score train:{}".format(r2_score(y_train, y_train_pred_l)))
 print("R2 score val:{}".format(r2_score(y_val, y_val_pred_l)) )<train_on_grid>
train = pd.read_csv(r'.. /input/train.csv',low_memory=True,index_col='ID_code')
 print(train.head(1))
train=reduce_mem_usage(train )
elas = ElasticNet()
params = {'alpha': [1000, 100, 10, 1, 0.1, 0.01, 0.001]}
cv_e = GridSearchCV(elas, params, cv = 10, n_jobs =1)
 cv_e.fit(X_train, y_train)
 print("Best params:{}".format(cv_e.best_params_))
best_e = cv_e.best_estimator_
y_train_pred_e = best_e.predict(X_train)
 y_val_pred_e = best_e.predict(X_val)
 print("MSE train:{}".format(mean_squared_error(y_train, y_train_pred_e)))
 print("MSE val;{}".format(mean_squared_error(y_val, y_val_pred_e)))
 print("R2 score train:{}".format(r2_score(y_train, y_train_pred_e)))
 print("R2 score val:{}".format(r2_score(y_val, y_val_pred_e)) )<predict_on_test>
train.replace(np.nan,0,inplace=True)
y_test_pred_f = best_f.predict(X_test)
 y_test_pred_x = best_x.predict(X_test)
 y_test_pred_lg = best_lg.predict(X_test)
 y_test_pred_g = best_g.predict(X_test)
 y_test_pred_r = best_r.predict(X_test)
 y_test_pred_l = best_l.predict(X_test)
 y_test_pred_e = best_e.predict(X_test)
 y_submit = 10**(( y_test_pred_f*0.05 + y_test_pred_x*0.10 + y_test_pred_lg*0.05 + y_test_pred_g*0.05 + y_test_pred_r*0.25 + y_test_pred_l*0.25 + y_test_pred_e*0.25))<save_to_csv>
test = pd.read_csv(r'.. /input/test.csv',low_memory=True,index_col='ID_code')
 test=reduce_mem_usage(test )
submit = pd.DataFrame({"Id":df_test["Id"], "SalePrice":y_submit})
 submit.to_csv('my_submission.csv', index=False)
 print("Your submission was successfully saved!" )<install_modules>
train = reduce_mem_usage(train )
!pip install pycaret==1.0<import_modules>
kf = StratifiedKFold(n_splits=5, shuffle=True, random_state=15)
import os
import random
import numpy as np
import pandas as pd<define_variables>
param = {
'boosting_type': 'gbdt',
'objective': 'binary',
'metric': 'auc',
'nthread': 6,
'learning_rate': 0.05,
'max_depth': 5,
'num_leaves': 40,
'sub_feature': 0.9,
'sub_row':0.9,
'bagging_freq': 1,
'lambda_l1': 0.1,
'lambda_l2': 0.1,
'random_state': 15,
'tree_learner':'serial',
'boost_from_average':'false'
}
def random_seed_initialize(seed=42):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed )<define_variables>
oof_preds = np.zeros(train.shape[0])
 sub_preds = np.zeros(len(test))
feature_importance_df = pd.DataFrame()
feats = [f for f in train.columns if f not in ['target']]
for n_fold,(train_idx, valid_idx)in enumerate(kf.split(train[feats], train['target'])) :
print(n_fold)
 trn_data = lgb.Dataset(train.iloc[train_idx][feats], label=train['target'].iloc[train_idx])
 val_data = lgb.Dataset(train.iloc[valid_idx][feats], label=train['target'].iloc[valid_idx])
 clf = lgb.train(param, trn_data,5120, valid_sets = [trn_data, val_data], verbose_eval=100, early_stopping_rounds = 200)
 oof_preds[valid_idx] = clf.predict(train.iloc[valid_idx][feats], num_iteration=clf.best_iteration)
 fold_importance_df = pd.DataFrame()
fold_importance_df["Feature"] = feats
fold_importance_df["importance"] = clf.feature_importance()
fold_importance_df["fold"] = n_fold + 1
feature_importance_df = pd.concat([feature_importance_df, fold_importance_df], axis=0)
 initial_idx = 0
chunk_size = 100000
current_pred = np.zeros(len(test))
while initial_idx < test.shape[0]:
final_idx = min(initial_idx + chunk_size, test.shape[0])
 idx = range(initial_idx, final_idx)
 current_pred[idx] = clf.predict(test.iloc[idx][feats], num_iteration=clf.best_iteration)
 initial_idx = final_idx
sub_preds += current_pred / 5
print('Full AUC score %.6f' % roc_auc_score(train['target'], oof_preds))
random_seed_initialize(777 )<load_from_csv>
train_data = pd.read_csv('.. /input/titanic/train.csv')
 test_data = pd.read_csv('.. /input/titanic/test.csv')
 submission_data = pd.read_csv('.. /input/titanic/gender_submission.csv' )<import_modules>
del train
gc.collect()
from pycaret.classification import *<drop_column>
<load_pretrained><EOS> 
output_xgb=pd.DataFrame({'ID_code':test.index,'target':sub_preds})
 output_xgb.to_csv(r'predictions.csv',index=False )