Skip to content

Instantly share code, notes, and snippets.

@parmarsuraj99
Created November 4, 2018 09:52
Show Gist options
  • Save parmarsuraj99/8dc7c231015df6b1f1e23245f6214110 to your computer and use it in GitHub Desktop.
Save parmarsuraj99/8dc7c231015df6b1f1e23245f6214110 to your computer and use it in GitHub Desktop.
Decision tree Classifier (sklearn)
from sklearn.datasets import load_iris #load dataset from scikitlearn
#This is a function which will return X and Y
from sklearn import tree
iris = load_iris() #load_iris() returns iris.data (x) and iris.target (Y)
clf = tree.DecisionTreeClassifier() #we create a Decision Tree Classifier from sklearn.tree
clf.fit(iris.data, iris.target) #Training
print("input: ", [4.9, 3.4, 2, 0.4]) #predictions
print("Prrediction: ", clf.predict([[4.9, 3.4, 2, 0.4]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment