import pandas as pd
%matplotlib inline
import numpy as np
import pydotplus 
from pandas.tools.plotting import scatter_matrix
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import tree
from sklearn.externals.six import StringIO
from sklearn.cross_validation import train_test_split
from sklearn import tree
from sklearn import metrics

iris_info = datasets.load_iris()
iris_info

x = iris.data[:,2:] 
y = iris.target

x

y

iris['feature_names']

dt = tree.DecisionTreeClassifier()

x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.5,train_size=0.5)

dt = dt.fit(x_train,y_train) 

def output(X,y,clf, show_accuracy=True, show_classification_report=True, show_confussion_matrix=True):
    y_pred=clf.predict(X)
    if show_accuracy:
        print("Accuracy:{0:.3f}".format(metrics.accuracy_score(y, y_pred)),"\n")
    if show_classification_report:
        print("Classification report")
        print(metrics.classification_report(y,y_pred),"\n")
    if show_confussion_matrix:
        print("Confusion matrix")
        print(metrics.confusion_matrix(y,y_pred),"\n")

output(x_train,y_train,dt)

output(x_test,y_test,dt)

"""
Explanation: We covered a lot of information today and I'd like you to practice developing classification trees on your own. For each exercise, work through the problem, determine the result, and provide the requested interpretation in comments along with the code. The point is to build classifiers, not necessarily good classifiers (that will hopefully come later)
1. Load the iris dataset and create a holdout set that is 50% of the data (50% in training and 50% in test). Output the results (don't worry about creating the tree visual unless you'd like to) and discuss them briefly (are they good or not?)
End of explanation
"""


x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.25,train_size=0.75)

output(x_train,y_train,dt)

output(x_test,y_test,dt)

"""
Explanation: Redo the model with a 75% - 25% training/test split and compare the results. Are they better or worse than before? Discuss why this may be.
End of explanation
"""


breast_cancer_data = datasets.load_breast_cancer()

type(breast_cancer_data)

breast_cancer_data

breast_cancer_data['feature_names']

print(type(breast_cancer_data.data))

print(breast_cancer_data.target_names)

print(breast_cancer_data.DESCR)

breast_cancer_df = pd.DataFrame(breast_cancer_data.data, columns=breast_cancer_data['feature_names'])
breast_cancer_df

breast_cancer_df['diagnosis']= breast_cancer_data.target

breast_cancer_df.corr()

"""
Explanation: Load the breast cancer dataset (datasets.load_breast_cancer()) and perform basic exploratory analysis. What attributes to we have? What are we trying to predict?
For context of the data, see the documentation here: https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Diagnostic%29
End of explanation
"""


x_seed = breast_cancer_data.data[:,:2]
y_seed = breast_cancer_data.target

x_seed

y_seed

x_train, x_test, y_train, y_test = split_test(x,y,test_size=0.5,train_size=0.5)

dt = dt.fit(x_train,y_train)

output(x_train,y_train,dt)

output(x_test,y_test,dt)

x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.25,train_size=0.75)

output(x_train,y_train,dt)

output(x_test,y_test,dt)

"""
Explanation: Using the breast cancer data, create a classifier to predict the type of seed. Perform the above hold out evaluation (50-50 and 75-25) and discuss the results.
End of explanation
"""


