%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()

"""
Explanation: <a href="http://www.datascience-paris-saclay.fr">Paris Saclay Center for Data Science</a>
Test <a href=http://www.ramp.studio/problems/iris>RAMP on iris</a>
<i> Balázs Kégl (LAL/CNRS)</i>
Introduction
Iris is a small standard multi-class classification data set from the <a href="http://archive.ics.uci.edu/ml/datasets/Iris">UCI Machine Learning Repository</a>.
End of explanation
"""


local_filename = 'data/train.csv'

# Open file and print the first 3 lines
with open(local_filename) as fid:
    for line in fid.readlines()[:3]:
        print(line)

data = pd.read_csv(local_filename)

data.head()

data.shape

data.describe()

data.hist(figsize=(10, 10), bins=50, layout=(3, 2));

sns.pairplot(data);

"""
Explanation: Fetch the data and load it in pandas
End of explanation
"""


data.head()

X_train = data.drop(columns='species')
y_train = data['species'].values

"""
Explanation: Building predictive models
First we will split our data into features and the target:
End of explanation
"""


from sklearn.ensemble import RandomForestClassifier

clf = RandomForestClassifier(n_estimators=1, max_leaf_nodes=2, random_state=61)

"""
Explanation: A basic predictive model using the scikit-learn random forest classifier will be presented below:
End of explanation
"""


from sklearn.model_selection import cross_val_score

scores = cross_val_score(clf, X_train, y_train, cv=8, scoring='accuracy')

print("mean: %e (+/- %e)" % (scores.mean(), scores.std()))

"""
Explanation: We can cross-validate our classifier (clf) using cross_val_score. Below we will have specified cv=8 meaning KFold cross-valdiation splitting will be used, with 8 folds. The accuracy classification score is calculated for each split. The output score will be an array of 8 scores from each KFold. The score mean and standard of the 8 scores is printed at the end.
End of explanation
"""


from sklearn.ensemble import RandomForestClassifier


def get_estimator():
    clf = RandomForestClassifier(n_estimators=1, max_leaf_nodes=2,
                                 random_state=61)
    return clf

"""
Explanation: RAMP submissions
For submitting to the RAMP site, you will need to write a submission.py file that defines a get_estimator function that returns a scikit-learn estimator.
For example, to submit our basic example above, we would define our classifier clf within the function and return clf at the end. Remember to include all the necessary imports at the beginning of the file.
End of explanation
"""


!ramp_test_submission

"""
Explanation: If you take a look at the sample submission in the directory submissions/starting_kit, you will find a file named classifier.py, which has the above code in it.
You can test that the sample submission works by running ramp_test_submission in your terminal (ensure that ramp-workflow has been installed and you are in the iris ramp kit directory). Alternatively, within this notebook you can run:
End of explanation
"""


