import readfile
import sklearn
import sklearn.preprocessing
import sklearn.model_selection
import sklearn.ensemble
import sklearn.metrics
from sklearn.neural_network import MLPClassifier

X, y = readfile.read_train('./part1/train_2008.csv')
X = X[:, 3:]
scaled_X = sklearn.preprocessing.scale(X, axis=0, with_mean=True, with_std=True, copy=True)

num_folds = 3
kf = sklearn.model_selection.KFold(n_splits=num_folds)
temp = []
# Iterate through cross-validation folds:
cv_auc = []
cv_auc1 = []
for train_index, test_index in kf.split(scaled_X):
    # Training and testing data points for this fold:
    x_train, x_test = scaled_X[train_index], scaled_X[test_index]
    y_train, y_test = y[train_index], y[test_index]

    clf = MLPClassifier(solver='adam', alpha=1e-2, hidden_layer_sizes=(300,300), activation='relu',early_stopping=True)
    clf.fit(x_train, y_train)
    pred_test = clf.predict_proba(x_test)[:,1]
    pred_train= clf.predict_proba(x_train)[:,1]

    fpr, tpr, thresholds = sklearn.metrics.roc_curve(y_test, pred_test, pos_label=1)
    cv_auc.append(sklearn.metrics.auc(fpr, tpr))

    fpr, tpr, thresholds = sklearn.metrics.roc_curve(y_train, pred_train, pos_label=1)
    cv_auc1.append(sklearn.metrics.auc(fpr, tpr))
    break
    #temp = pred
#print(temp[:1000])
print(cv_auc)
print(cv_auc1)