Kaggle competition: Don't Overfit! II
%matplotlib inline 
<load_from_csv>
pd.set_option('display.max_columns', None)
 %matplotlib inline
data = pd.read_csv('.. /input/application_train.csv')
 test = pd.read_csv('.. /input/application_test.csv')
 prev = pd.read_csv('.. /input/previous_application.csv')
 buro = pd.read_csv('.. /input/bureau.csv')
 buro_balance = pd.read_csv('.. /input/bureau_balance.csv')
 credit_card = pd.read_csv('.. /input/credit_card_balance.csv')
 POS_CASH = pd.read_csv('.. /input/POS_CASH_balance.csv')
 payments = pd.read_csv('.. /input/installments_payments.csv' )<import_modules>
py.init_notebook_mode(connected=True )
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import KFold<import_modules>
def get_train_data() :
filename = os.path.join(data_dir, 'train.csv')
 train = pd.read_csv(filename, index_col=0)
 X_train = train.iloc[:, 1:]
y_train = train['target']
return X_train, y_train
def get_test_data() :
filename = os.path.join(data_dir, 'test.csv')
 test = pd.read_csv(filename, index_col=0)
 return test
import xgboost as xgb
from xgboost import XGBClassifier
import gc<import_modules>
log_clf = LogisticRegression(random_state=42)
 param_grid = {
'class_weight' : ['balanced', None],
'penalty' : ['l2','l1'],
'C' : [0.001, 0.01, 0.1, 1, 10, 100, 1000],
'solver' : ['liblinear', 'saga'],
}
grid = GridSearchCV(estimator=log_clf, cv=5, param_grid=param_grid,
scoring='roc_auc', verbose=1, n_jobs=-1)
 grid.fit(X_train, y_train)
 print("Best Score: {0}".format(grid.best_score_))
print("Best Parameters: {0}".format(grid.best_params_))
best_parameters = grid.best_params_
from sklearn.preprocessing import MinMaxScaler, LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, roc_auc_score, confusion_matrix
from sklearn.feature_selection import VarianceThreshold<import_modules>
log_clf = LogisticRegression(**best_parameters)
 log_clf.fit(X_train, y_train)
 selector = RFE(log_clf, 25, step=1)
 selector.fit(X_train, y_train)
 scores_table(selector, X_train, y_train, 'selector_clf', n_splits=10 )
from sklearn.model_selection import GridSearchCV
from skopt import BayesSearchCV
from sklearn.model_selection import train_test_split, KFold, StratifiedKFold<find_best_params>
y_test = log_clf.predict_proba(X_test )
def status_print(optim_result):

 all_models = pd.DataFrame(bayes_cv_tuner.cv_results_)
 best_params = pd.Series(bayes_cv_tuner.best_params_)
 print('Model
Best ROC-AUC: {}
Best params: {}
'.format(
 len(all_models),
np.round(bayes_cv_tuner.best_score_, 4),
bayes_cv_tuner.best_params_ 
))
clf_name = bayes_cv_tuner.estimator.__class__.__name__
all_models.to_csv(clf_name+"_cv_results.csv" )<prepare_x_and_y>
filename = os.path.join(data_dir, 'sample_submission.csv')
 submission = pd.read_csv(filename)
 filename = os.path.join(output_dir, 'submission.csv')
 submission['target'] = y_test
submission.to_csv('submission.csv', index=False)
 submission.head()