python 数据科学 - 【分类模型】 ☞ 逻辑回归


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()  




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

PeersLee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值