数据分析 Logistics 与 DecisionTree 案例

from sklearn.datasets import make_blobs
data,target =make_blobs()
plt.scatter(data[:,0],data[:,1],c=target)

数据分析 Logistics 与 DecisionTree 案例_第1张图片

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张图片

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张图片

你可能感兴趣的:(技术信息)