Decision Tree
In [19]:
from sklearn import tree
X=[[0,0],[1,1]]
y=[0,1]
clf=tree.DecisionTreeClassifier()
clf=clf.fit(X,y)
In [18]:
clf.predict([[2.,2.]])
Out[18]:
In [20]:
clf.predict_proba([[2.0,2.0]])
Out[20]:
In [21]:
from sklearn.datasets import load_iris
from sklearn import tree
iris=load_iris()
clf=tree.DecisionTreeClassifier()
clf=clf.fit(iris.data, iris.target)
In [22]:
with open('iris.dot','w') as f:
f=tree.export_graphviz(clf,out_file=f)
In [23]:
import os
os.unlink('iris.dot')
In [25]:
from IPython.display import Image
import pydotplus
dot_data=tree.export_graphviz(clf, out_file=None,
feature_names=iris.feature_names,
class_names=iris.target_names,
filled=True, rounded=True,
special_characters=True)
graph=pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())
In [15]:
from sklearn import tree
X = [[0,0],[2,2]]
y = [0.5,2.5]
clf=tree.DecisionTreeRegressor()
clf=clf.fit(X,y)
clf.predict([[1,1]])
Out[15]: