In [1]:
import pandas as pd
%matplotlib inline
from sklearn import datasets
from sklearn import tree
import matplotlib.pyplot as plt
In [2]:
iris = datasets.load_iris() # load iris data set
In [3]:
x = iris.data[:,2:] # the attributes
y = iris.target # the target variable
In [4]:
dt = tree.DecisionTreeClassifier()
In [5]:
dt = dt.fit(x,y)
In [6]:
from sklearn.cross_validation import cross_val_score
In [7]:
# http://scikit-learn.org/stable/modules/cross_validation.html#computing-cross-validated-metrics
scores = cross_val_score(dt,x,y,cv=10) #We're passing in our values and getting an array of values back
In [8]:
import numpy as np
In [9]:
np.mean(scores) #here we get our average result
Out[9]:
In [ ]: