Kaggle competition: Cloud Faculty Institute Workshop
<SOS> metric: meanfscore Kaggle data source: cloud-faculty-institute-workshop<randomize_order>
%matplotlib inline
use_col = imp.index[:55]<train_model>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )
%%time
clf.fit(X_train_[use_col], y_train_, early_stopping_rounds=20, eval_metric='auc', eval_set=[(X_val[use_col], y_val)] )<train_model>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )
scores = []
y_pred_test = np.zeros(len(X_test[use_col]))
skf = StratifiedKFold(n_splits=10, random_state=2020, shuffle=True)
 for i,(train_ix, test_ix)in enumerate(tqdm(skf.split(X_train[use_col], y_train))):
X_train_, y_train_ = X_train[use_col].iloc[train_ix], y_train.iloc[train_ix]
X_val, y_val = X_train[use_col].iloc[test_ix], y_train.iloc[test_ix ]
clf = LGBMClassifier(max_depth=50, n_estimators=500, num_leaves=100, learning_rate=0.1, silent=False)
 clf.fit(X_train_[use_col], y_train_, early_stopping_rounds=200, eval_metric='auc', eval_set=[(X_val, y_val)])
 y_pred = clf.predict_proba(X_val)[:,1]
scores = np.append(scores, roc_auc_score(y_val, y_pred))
y_pred_test += clf.predict_proba(X_test[use_col])[:,1]
scores = np.array(scores)
 print('Ave.CV score is %f' % scores.mean() )<train_model>
imputer = Imputer()
train2 =train[['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness',
'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age',]].replace(0, numpy.NaN)
 train2["Outcome"]= train["Outcome"]
transformed_train = imputer.fit_transform(train2)
 print(numpy.isnan(transformed_train ).sum())
 train2.BMI.plot()
print(train2.shape)
skf = StratifiedKFold(n_splits=10, random_state=71, shuffle=True)
 for i,(train_ix, test_ix)in enumerate(tqdm(skf.split(X_train[use_col], y_train))):
X_train_, y_train_ = X_train[use_col].iloc[train_ix], y_train.iloc[train_ix]
X_val, y_val = X_train[use_col].iloc[test_ix], y_train.iloc[test_ix ]
clf = LGBMClassifier(max_depth=50, n_estimators=500, num_leaves=100, learning_rate=0.1, silent=False)
 clf.fit(X_train_[use_col], y_train_, early_stopping_rounds=200, eval_metric='auc', eval_set=[(X_val, y_val)])
 y_pred = clf.predict_proba(X_val)[:,1]
scores = np.append(scores, roc_auc_score(y_val, y_pred))
y_pred_test += clf.predict_proba(X_test[use_col])[:,1]
scores = np.array(scores)
 print('Ave.CV score is %f' % scores.mean() )<train_model>
train.isnull().sum()
skf = StratifiedKFold(n_splits=10, random_state=42, shuffle=True)
 for i,(train_ix, test_ix)in enumerate(tqdm(skf.split(X_train[use_col], y_train))):
X_train_, y_train_ = X_train[use_col].iloc[train_ix], y_train.iloc[train_ix]
X_val, y_val = X_train[use_col].iloc[test_ix], y_train.iloc[test_ix ]
clf = LGBMClassifier(max_depth=50, n_estimators=500, num_leaves=100, learning_rate=0.1, silent=False)
 clf.fit(X_train_[use_col], y_train_, early_stopping_rounds=200, eval_metric='auc', eval_set=[(X_val, y_val)])
 y_pred = clf.predict_proba(X_val)[:,1]
scores = np.append(scores, roc_auc_score(y_val, y_pred))
y_pred_test += clf.predict_proba(X_test[use_col])[:,1]
scores = np.array(scores)
 print('Ave.CV score is %f' % scores.mean() )<train_model>
test.isnull().sum()
skf = StratifiedKFold(n_splits=10, random_state=1, shuffle=True)
 for i,(train_ix, test_ix)in enumerate(tqdm(skf.split(X_train[use_col], y_train))):
X_train_, y_train_ = X_train[use_col].iloc[train_ix], y_train.iloc[train_ix]
X_val, y_val = X_train[use_col].iloc[test_ix], y_train.iloc[test_ix ]
clf = LGBMClassifier(max_depth=50, n_estimators=500, num_leaves=100, learning_rate=0.1, silent=False)
 clf.fit(X_train_[use_col], y_train_, early_stopping_rounds=200, eval_metric='auc', eval_set=[(X_val, y_val)])
 y_pred = clf.predict_proba(X_val)[:,1]
scores = np.append(scores, roc_auc_score(y_val, y_pred))
y_pred_test += clf.predict_proba(X_test[use_col])[:,1]
scores = np.array(scores)
 print('Ave.CV score is %f' % scores.mean() )<train_model>
test.isnull().sum()
skf = StratifiedKFold(n_splits=10, random_state=0, shuffle=True)
 for i,(train_ix, test_ix)in enumerate(tqdm(skf.split(X_train[use_col], y_train))):
X_train_, y_train_ = X_train[use_col].iloc[train_ix], y_train.iloc[train_ix]
X_val, y_val = X_train[use_col].iloc[test_ix], y_train.iloc[test_ix ]
clf = LGBMClassifier(max_depth=50, n_estimators=500, num_leaves=100, learning_rate=0.1, silent=False)
 clf.fit(X_train_[use_col], y_train_, early_stopping_rounds=200, eval_metric='auc', eval_set=[(X_val, y_val)])
 y_pred = clf.predict_proba(X_val)[:,1]
scores = np.append(scores, roc_auc_score(y_val, y_pred))
y_pred_test += clf.predict_proba(X_test[use_col])[:,1]
scores = np.array(scores)
 print('Ave.CV score is %f' % scores.mean() )<feature_engineering>
train.Outcome.value_counts()
y_pred_test /= 50<save_to_csv>
X = train2.drop(['Outcome'], axis = 1)
 imputer = Imputer()
transformed_X = imputer.fit_transform(X)
 X_with_null = train.drop(['Outcome'], axis = 1)
 y = train2.Outcome
y_with_null = train.Outcome
submission = pd.read_csv('.. /input/homework-for-students4plus/sample_submission.csv', index_col=0)
 submission.loan_condition = y_pred_test
submission.to_csv('submission.csv' )<import_modules>
X_validate = X[:200]
Y_validate = y[:200]
params = {'learning_rate':0.1}
model = XGBClassifier(n_estimators=500, **params)
 kfold = KFold(n_splits=10, random_state=7)
 print("dropped nulls")
 print(cross_val_score(model, transformed_X, y,cv=kfold))
%matplotlib inline
pd.options.display.max_rows = 1000
pd.options.display.max_columns = 200
DIR = '/kaggle/input/homework-for-students4plus'<define_variables>
X_validate_null = X_with_null[:200]
Y_validate_null = y_with_null[:200]
params = {'learning_rate':0.1}
model = XGBClassifier(n_estimators=500, **params)
 kfold = KFold(n_splits=10, random_state=7)
 print("Raw data")
 print(cross_val_score(model, X_validate_null, Y_validate_null,cv=kfold))
df_train_ori, df_test_ori = None, None
df_train, df_test = None, None
df_holdout = None
df_train_linear, df_test_linear = None, None
sr_title_train, sr_title_test = None, None
sr_emp_title_train, sr_emp_title_test = None, None
tfidf_pca_title_train, tfidf_pca_title_test = None, None
tfidf_pca_emp_title_train, tfidf_pca_emp_title_test = None, None
tfidf_pca_kmeans_cluster_train, tfidf_pca_kmeans_cluster_test = None, None
tfidf_pca_logreg_prediction_train, tfidf_pca_logreg_prediction_test = None, None
records_pca_tsne_kmeans_cluster_train, records_pca_tsne_kmeans_cluster_test = None, None
recoeds_kmeans_cluster_train, recoeds_kmeans_cluster_test = None, None<define_variables>
XX = pd.DataFrame(data=transformed_X)
 XX.columns = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness',
'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age']
XX['Id'] = train['Id']
XX.head()
cols_qualitative, cols_quantitative, cols_flg = [], [], []
cols_unnecessary = []
y_pred_final = None
y_preds_list_for_ensemble = []
score_cv_avr, score_holdout = None, None
cvscore_list_for_ensemble, holdoutscore_list_for_ensemble = [], []
lgbm_params = {'objective': 'binary', 'metric': 'auc', 'learning_rate': 0.05}<import_modules>
params = {'learning_rate':0.01}
clf = XGBClassifier(n_estimators=100, **params)
 clf.fit(XX,y )
def get_cols_to_use() :
global cols_qualitative, cols_quantitative, cols_flg
return cols_qualitative+cols_quantitative+cols_flg<load_pretrained>
predicted = clf.predict(test)
<feature_engineering><EOS> 
output = pd.DataFrame(predicted,columns = ['Outcome'])
 test = pd.read_csv('.. /input/test.csv')
 output['Id'] = test['Id']
output[['Id','Outcome']].to_csv('johnnybgood2.csv', index = False)
 output.head()