from sklearn.datasets import make_blobs
data,target =make_blobs()
plt.scatter(data[:,0],data[:,1],c=target)
![数据分析 Logistics 与 DecisionTree 案例_第1张图片](http://img.e-com-net.com/image/info8/e643a342b6bc4f0994737630a652b6cb.jpg)
from sklearn.linear_model import LogisticRegression
logistic = LogisticRegression(solver='liblinear',multi_class='auto')
logistic.fit(data,target)
logistic.score(data,target)
x, y = np.linspace(data[:,0].min(), data[:,0].max(), 1000), np.linspace(data[:,1].min(), data[:,1].max(), 1000)
X, Y = np.meshgrid(x,y)
XY = np.c_[X.ravel(), Y.ravel()]
y_ = logistic.predict(XY)
plt.pcolormesh(X, Y, y_.reshape(1000,1000))
plt.scatter(data[:,0], data[:,1], c=target, cmap='rainbow')
![数据分析 Logistics 与 DecisionTree 案例_第2张图片](http://img.e-com-net.com/image/info8/674a9496116f4e85b56ce7cc30230130.jpg)
from sklearn.tree import DecisionTreeClassifier
tree = DecisionTreeClassifier(max_depth=5)
tree.fit(data,target)
tree.score(data,target)
x, y = np.linspace(data[:,0].min(), data[:,0].max(), 1000), np.linspace(data[:,1].min(), data[:,1].max(), 1000)
X, Y = np.meshgrid(x, y)
XY = np.c_[X.ravel(), Y.ravel()]
y_ = tree.predict(XY)
plt.pcolormesh(X, Y, y_.reshape(1000,1000))
plt.scatter(data[:,0], data[:, 1], c=target, cmap='rainbow')
![数据分析 Logistics 与 DecisionTree 案例_第3张图片](http://img.e-com-net.com/image/info8/a550925ea9ed476ab183928ebe52a118.jpg)