逻辑回归

jupyter里查看函数用法:

点到函数,再shift+tab

运行一下函数

shift+enter
image
image
image
image
image
image
image
image

逻辑回归的梯度下降的代码

numpy.concatenate()函数

np.concatenate((a,b),axis=1) #axis=1表示对应行的数组进行拼接,横着加
np.concatenate((a,b),axis=0) # axis=0为按列拼接,竖着加
不写axis参数的话,默认为按列拼接;
若axis = -1的话,即为按行拼接:

y_data = data[:,-1,np.newaxis]

增加了一个维度,一维变成二维

np.multiply

矩阵的按位子相乘
1,2 |2,3
3,4 |2,4

2,6
6,16

image

#画图例

plt.legend(handles=[scatter0,scatter1],labels=['label0','label1'],loc='best')
best是自动选择最佳的位置
image

np.ones((100,1))

np.ones()函数返回给定形状和数据类型的新数组,其中元素的值设置为1。
难点:
image
因为:
image

https://github.com/xinxuann/MachineLearningNote/blob/main/逻辑回归/梯度下降法-逻辑回归.ipynb

逻辑回归的sklearn的代码

image

coef_和intercept_总结

coef_和intercept_都是模型参数,即为w
coef_为w1到w4
intercept_为w0
intercept:截距

classification_report

sklearn中的classification_report函数用于显示主要分类指标的文本报告.在报告中显示每个类的精确度,召回率,F1值等信息。
https://github.com/xinxuann/MachineLearningNote/blob/main/逻辑回归/sklearn-逻辑回归.ipynb

posted @ 2022-10-18 16:50  辛宣  阅读(43)  评论(0)    收藏  举报