Skip to content

Instantly share code, notes, and snippets.

@sagz
Created April 16, 2014 17:13
Show Gist options
  • Save sagz/10908945 to your computer and use it in GitHub Desktop.
Save sagz/10908945 to your computer and use it in GitHub Desktop.
# Decision Tree Classifier
from sklearn import datasets
from sklearn import metrics
from sklearn.tree import DecisionTreeClassifier
# load the iris datasets
dataset = datasets.load_iris()
# fit a CART model to the data
model = DecisionTreeClassifier()
model.fit(dataset.data, dataset.target)
print(model)
# make predictions
expected = dataset.target
predicted = model.predict(dataset.data)
# summarize the fit of the model
print(metrics.classification_report(expected, predicted))
print(metrics.confusion_matrix(expected, predicted))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment