Skip to content

Instantly share code, notes, and snippets.

@vaibhav-jain
Created July 30, 2017 17:09
Show Gist options
  • Save vaibhav-jain/adbb24a6afc7231505dda8baa74e4f66 to your computer and use it in GitHub Desktop.
Save vaibhav-jain/adbb24a6afc7231505dda8baa74e4f66 to your computer and use it in GitHub Desktop.
Solving classical Iris problem using machine learning.
#!/usr/bin/env python
import numpy as np
from sklearn import tree
from sklearn.datasets import load_iris
iris = load_iris()
test_tdx = [0, 50, 100]
# training data
train_target = np.delete(iris.target, test_tdx)
train_data = np.delete(iris.data, test_tdx, axis=0)
# testing data
test_data = iris.data[test_tdx]
test_target = iris.target[test_tdx]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(train_data, train_target)
print test_target
print clf.predict(test_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment