<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 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)
Step1:  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?)
Step2:  2. 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.
Step3:  3. Load the breast cancer dataset (datasets.load_breast_cancer()) and perform basic exploratory analysis. What attributes do we have? What are we trying to predict?
For context of the data, see the documentation here
Step4:  4. 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.
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline 
from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn import tree
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)
End of explanation
iris = datasets.load_iris()
x = iris.data[:,2:] #attributes
y = iris.target #target variable
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)
from sklearn import metrics
import numpy as np
def measure_performance(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")
measure_performance(x_test,y_test,dt)
#Accuracy: Out of all the predicted outcomes (true positive, false positive, true negative, false negative), how many are true positives or negatives?
# a score of .973 means that 97.3 percent of those classifed were true positives and true negatives. 
# While 2.7 percent were false positives (said to be true when it was false) or
# false negatives (said to be false when it was true )
#Precision: When the condition was predicted to be true (true positives, false positives), 
#how many of those 'true' predictions were true positives 
#a score of 1 means that all of the cases predicted to be true were true positives 
#a score of .93 means 93 percent of those classified as 1 were in class 1 (tp)
#while 7 percent of those classified as 1 were not in class 1 (fp, we said it was true when it was false)
#Recall: When the actual condition was true,how many were predicted true positives? 
#a score of 1 means that all the cases that were actually true were predicted to be true
#a score of .9 means that when the actual condition was true, 90% were predicted to be true, and 10% were predicted
#to be false (false negatives, we said it was false when it was true)
#confusion matrix: rows are the actual condition: class 0, class 1, class 2
#columns are the predicted conditions, predicted_class 0, predicted_class 1, predicted class 2
#so the matrix tells us that when the class was actually 2, we predicted it was class 1 twice
Explanation: 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)
dt = dt.fit(x_train,y_train)
measure_performance(x_test,y_test,dt)
# they're worse, in a way. 
# but i suspect that the first model was overfitting the data. 
Explanation: 2. 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 = datasets.load_breast_cancer()
breast_cancer['feature_names']
breast_cancer['target']
Explanation: 3. Load the breast cancer dataset (datasets.load_breast_cancer()) and perform basic exploratory analysis. What attributes do 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 = breast_cancer.data[:,:]
y = breast_cancer.target
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)
measure_performance(x_test,y_test,dt)
# when benign (0), 16 cases were said to be malignant when they were not
# when malignant (1), 7 cases were said to be benign when they were not 
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.25,train_size=0.75)
dt = dt.fit(x_train,y_train)
measure_performance(x_test,y_test,dt)
# the model is better.
# when when the actual case was benign, it predicted that it was malignant 4 times 
# when the actual case when malignant, it predicted that it was benign once. 
# perhaps this is because the data set is larger, and there is a relationship between the size of data set and
# the split between training and testing 
Explanation: 4. 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
<END_TASK>