Kaggle competition: Santander Customer Transaction Prediction
df.loc[(df.GarageFinish.isnull())&(df.GarageType.notnull()), "GarageFinish"] = "Fin"
df.loc[(df.GarageCars.isnull())&(df.GarageType.notnull()), "GarageCars"] = 1
df.loc[(df.GarageQual.isnull())&(df.GarageType.notnull()), "GarageQual"] = "TA"
df.loc[(df.GarageCond.isnull())&(df.GarageType.notnull()), "GarageCond"] = "TA"<filter>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 print(train.shape, test.shape )
df[df.GarageYrBlt == df.YearBuilt].shape[0]<feature_engineering>
df.loc[(df.GarageYrBlt.isnull())&(df.GarageType.notnull()), "GarageYrBlt"] = df.loc[(df.GarageYrBlt.isnull())&(df.GarageType.notnull())].YearBuilt<define_variables>
melted1 = pd.melt(train.iloc[:, np.r_[1, 2:42]], id_vars='target')
 melted2 = pd.melt(train.iloc[:, np.r_[1, 42:82]], id_vars='target')
 melted3 = pd.melt(train.iloc[:, np.r_[1, 82:122]], id_vars='target')
 melted4 = pd.melt(train.iloc[:, np.r_[1, 122:162]], id_vars='target')
 melted5 = pd.melt(train.iloc[:, np.r_[1, 162:202]], id_vars='target' )
df[(df.GarageType == "Detchd")&(df.YearBuilt < 1930)&(df.YearRemodAdd < 2000)&(df.YearRemodAdd > 1980)&(df.GarageCars == 1)].GarageArea.median()<feature_engineering>
logit_mod = sm.Logit(train['target'], train.iloc[:, 2:])
 logit_res = logit_mod.fit(disp=0)
 print(logit_res.summary() )
df.loc[(df.GarageArea.isnull())&(df.GarageType.notnull()), "GarageArea"] = 234<define_variables>
import lightgbm as lgb
from sklearn.metrics import accuracy_score, roc_auc_score, confusion_matrix
from sklearn.model_selection import StratifiedKFold
num_cols, cat_cols, ord_cols = col_types(df )<correct_missing_values>
param = {
'num_leaves': 5,
'max_depth': 15,
'save_binary': True,
'seed': 42,
'objective': 'binary',
'boosting_type': 'gbdt',
'verbose': 1,
'metric': 'auc',
'is_unbalance': True,
}
none_cols = ["PoolQC", "MiscFeature", "Alley", "Fence", "FireplaceQu", "GarageCond", "GarageFinish", "GarageQual",
"GarageType", "BsmtExposure", "BsmtCond", "BsmtQual", "BsmtFinType1", "MasVnrType", "BsmtFinType2"]
for col in none_cols:
df[col].fillna("None", inplace=True)
 missing(df )<feature_engineering>
train_preds = np.zeros(len(train))
test_preds = np.zeros(len(test))
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
 for train_index, valid_index in skf.split(train[variables], train['target']):
train_data = lgb.Dataset(train.loc[train_index, variables],
label=train.loc[train_index, 'target'])
 valid_data = lgb.Dataset(train.loc[valid_index, variables],
label=train.loc[valid_index, 'target'])
 bst = lgb.train(param, train_data, num_boost_round=2000, valid_sets=valid_data,
verbose_eval=500, early_stopping_rounds=30)
 train_preds[valid_index] = bst.predict(train.loc[valid_index, variables],
num_iteration=bst.best_iteration)
 test_preds += bst.predict(test[variables], num_iteration=bst.best_iteration)/ 5
print('Accuracy {}'.format(accuracy_score(train['target'], np.where(train_preds > 0.5, 1, 0))))
print('ROC AUC Score: {}'.format(roc_auc_score(train['target'], train_preds)) )
<data_type_conversions><EOS> 
submission = pd.DataFrame({'ID_code': test['ID_code'],
'target': test_preds})
 submission.to_csv('submission.csv', index=False )