Skip to content

Instantly share code, notes, and snippets.

@d8aninja
Last active August 29, 2015 14:07
Show Gist options
  • Save d8aninja/75efb40f3c709626820a to your computer and use it in GitHub Desktop.
Save d8aninja/75efb40f3c709626820a 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