Kaggle competition: Santander Customer Satisfaction
classifier = MLPClassifier()
parameter_space = {
'hidden_layer_sizes': [(50,50,50),(100,100,100),(150,150,150),(200,200,200)],
'activation': ['tanh', 'relu', 'logistic'],
'solver': ['sgd', 'adam'],
'alpha': [0.0001, 0.05],
'learning_rate': ['constant','adaptive'],
}<train_on_grid>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
model = GridSearchCV(classifier, parameter_space, n_jobs=-1, cv=3)
 model.fit(x_train_scaled, y_train )<train_model>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
print('Best parameters calculated :', model.best_params_ )<predict_on_test>
train.loc[train["var3"]==-999999,"var3"] = 2
all_clomuns = list(train.columns.values)
 all_clomuns.remove("ID")
 all_clomuns.remove("TARGET")
 f_values, p_values = f_classif(train[all_clomuns], train["TARGET"])
 p_values = -np.log10(p_values)
 p_values_dict = {}
for idx,value in enumerate(p_values):
if value not in p_values_dict:
p_values_dict[value] = [all_clomuns[idx]]
else:
p_values_dict[value].append(all_clomuns[idx])
 identical_pvalues = []
for value in p_values_dict.keys() :
if(len(p_values_dict[value])>1):
for name in p_values_dict[value][1:]:
all_clomuns.remove(name )
predicted_y = model.predict(x_test_scaled)
<compute_test_metric>
train2 = train[all_clomuns]
corrMatrix=train2.corr()
corrMatrix.loc[:,:] = np.tril(corrMatrix, k=-1)
 already_in = set()
result = []
for col in corrMatrix:
perfect_corr = corrMatrix[col][corrMatrix[col] > 0.9].index.tolist()
if perfect_corr and col not in already_in:
already_in.update(set(perfect_corr))
perfect_corr.append(col)
 result.append(perfect_corr)
 for pair in result:
for name in pair[1:]:
if name in all_clomuns:
all_clomuns.remove(name )
confusion = confusion_matrix(y_test, predicted_y)
 print('Confusion Matrix after hyperparameter optimization
', confusion)
 print('Accuracy after hyperparameter optimization: {:.2f}'.format(accuracy_score(y_test, predicted_y)) )<train_model>
y_train = train['TARGET'].values
X_train = train[all_clomuns].values
id_test = test['ID']
X_test = test[all_clomuns].values
len_train = len(X_train)
 len_test = len(X_test)
 clf = xgb.XGBClassifier(missing=np.nan, max_depth=6, n_estimators=500, learning_rate=0.02, nthread=4, subsample=0.75, colsample_bytree=0.75, seed=1024)
 X_fit, X_eval, y_fit, y_eval= train_test_split(X_train, y_train, test_size=0.3)
 clf.fit(X_train, y_train, early_stopping_rounds=30, eval_metric="auc", eval_set=[(X_eval, y_eval)],verbose=1)
 y_pred= clf.predict_proba(X_test)[:,1]
submission = pd.DataFrame({"ID":id_test, "TARGET":y_pred})
 submission.to_csv("submission6.csv", index=False )