from evoml.subsampling import BasicSegmenter_FEMPO, BasicSegmenter_FEGT, BasicSegmenter_FEMPT

df = pd.read_csv('datasets/ozone.csv')

df.head(2)

X, y = df.iloc[:,:-1], df['output']

print(BasicSegmenter_FEGT.__doc__)

from sklearn.tree import DecisionTreeRegressor
clf_dt = DecisionTreeRegressor(max_depth=3)
clf = BasicSegmenter_FEGT(base_estimator=clf_dt, statistics=True)

clf.fit(X, y)

clf.score(X, y)

EGs = clf.segments_

len(EGs)

sampled_datasets = [eg.get_data() for eg in EGs]

[sd.shape for sd in sampled_datasets]

"""
Explanation: Aim
Motive of the notebook is to give a brief overview as to how to use the evolutionary sampling powered ensemble models as part of the EvoML research project. 
Will make the notebook more verbose if time permits. Priority will be to showcase the flexible API of the new estimators which encourage research and tinkering. 
Contents

Subsampling
Subspacing

1. Subsampling - Sampling in the example space - rows will be mutated and evolved.
End of explanation
"""


from evoml.subspacing import FeatureStackerFEGT, FeatureStackerFEMPO

print(FeatureStackerFEGT.__doc__)

clf = FeatureStackerFEGT(ngen=30)

clf.fit(X, y)

clf.score(X, y)

## Get the Hall of Fame individual
hof = clf.segment[0]

sampled_datasets = [eg.get_data() for eg in hof]

[data.columns.tolist() for data in sampled_datasets]

## Original X columns
X.columns

# The exploration of the dataset by benchmark algorithms
clf = DecisionTreeClassifier(random_state=34092)
clf.fit(X_train, y_train)
pred_DTC = clf.predict(X_test)
print('Base DecisionTreeClassifier accuracy: {}'.format(clf.score(X_test, y_test)))

clf = RandomForestClassifier(random_state=34092)
clf.fit(X_train_tot, y_train)
pred_RFC = clf.predict(X_test)
print('Base RandomForestClassifier accuracy: {}'.format(clf.score(X_test, y_test)))

clf = GradientBoostingClassifier(random_state=34092)
clf.fit(X_train, y_train)
pred_GBC = clf.predict(X_test)
print('Base GradientBoostingClassifier accuracy: {}'.format(clf.score(X_test, y_test)))

print('')

"""
Explanation: 2. Subspacing - sampling in the domain of features - evolving and mutating columns
End of explanation
"""


import pandas as pd
df = pd.read_csv('datasets/ozone.csv')
X, y = df.iloc[:,:-1], df['output']
from evoml.subspacing import FeatureStackerFEGT, FeatureStackerFEMPO, FeatureStackerFECV
#print(FeatureStackerFECV.__doc__)
clf = FeatureStackerFECV(ngen=3)
clf.fit(X, y)
clf.predict(X)

import numpy as np
import pandas as pd
from evoml.subspacing import FeatureStackerFEGT, FeatureStackerFEMPO, FeatureStackerFECV
from sklearn.cross_validation import train_test_split


data = pd.read_csv('datasets/GAMETES.csv',sep='\t')
headers_ = list(data.columns)

features = data[headers_[0:-1]]
output = data[headers_[-1]]

X_train, X_test, y_train, y_test = train_test_split(features, output, stratify=output,
                                                        train_size=0.75, test_size=0.25)


from sklearn.tree import DecisionTreeClassifier
clf_dt = DecisionTreeClassifier(max_features=None)
clf = FeatureStackerFECV(ngen=20, model_type='classification', base_estimator=clf_dt, folds_CV=10)
clf.fit(X_train, y_train)


from sklearn.metrics import accuracy_score
pred = clf.predict(X_test)
accuracy_score(pred, y_test)

StratifiedKFold?

"""
Explanation: FECV
End of explanation
"""


