
import sys
import os

from sklearn.ensemble import GradientBoostingClassifier
from sklearn import preprocessing
import pandas as pd

sys.path.append(os.path.abspath(os.path.join('..')))
import stdfunc


def main():

    df_train = pd.read_csv('../train_dataset.csv')
    df_test = pd.read_csv('../test_dataset.csv')

    X_train, y_train = df_train.iloc[:, 2:], df_train.iloc[:, 0]
    X_test, y_test = df_test.iloc[:, 2:], df_test.iloc[:, 0]
    unique_labels = sorted(y_train.unique().tolist())

    # hyper-parameters inferred by running auto-sklearn
    clf = GradientBoostingClassifier(learning_rate=0.0433556140045585,
        n_estimators=388, subsample=0.8291104221904706, criterion='mse',
        min_samples_split=13, min_samples_leaf=15,
        max_depth=10, max_features=0.33000096635982235, verbose=True)

    # hyper parameters inferred by running hyperopt-sklearn
    # clf = GradientBoostingClassifier(criterion="mse", learning_rate=0.28539836866041823, max_depth=9, max_features=0.3842196341383438,
    #                                  min_samples_leaf=14, min_samples_split=9, n_estimators=734, subsample=0.7421091918485163)

    clf.fit(X_train, y_train)

    print("\n\n{}\n".format(clf.score(X_test, y_test)))

    y_predicted = clf.predict(X_test)

    print("Generating confusion matrix figure... \n")
    stdfunc.plot_confusion_matrix(y_test, y_predicted, ml_name='DT',
                                  classes=unique_labels,
                                  title='Confusion matrix for Decision Tree evaluation')

    print("Generating classification report figure... \n")
    stdfunc.plot_classification_report(y_test, y_predicted, ml_name='DT',
                                       classes=unique_labels,
                                       title='Classification report for Decision Tree evaluation')


if __name__ == '__main__':
    main()
