sklearn.linear_model.LogisticRegression
'''
逻辑回归是二元分析,其分析结果为一个0-1之间的概率,所以其分界线可以为斜线
'''
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
import numpy as np
import matplotlib.pyplot as plt
iris = load_iris()
X = iris.data[:, [2,3]]
Y = iris.target
clf = LogisticRegression()
clf.fit(X, Y)
x0_min, x0_max = X[:, 0].min() - 1, X[:, 0].max() + 1
x1_min, x1_max = X[:, 1].min() - 1, X[:, 1].max() + 1
# 产生一个以向量xx为行,向量yy为列的矩阵
xx, yy = np.meshgrid(np.arange(x0_min, x0_max, 0.1),
np.arange(x1_min, x1_max, 0.1)) # 等高线的网格数据
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
zz = Z.reshape(xx.shape)
plt.plot()
plt.contourf(xx, yy , zz, alpha=0.5, cmap=plt.cm.rainbow) #alpha 透明度,cmap 颜色
plt.scatter(X[:, 0], X[:, 1], c=Y, alpha=1, cmap=plt.cm.RdYlBu) #c 颜色序列
plt.title('Decision Tree')
plt.xlabel('Petal.Length')
plt.ylabel('Petal.Width')
plt.show()