逻辑回归,是一种用回归思想解决二分类问题的算法。它是用线性模型去拟合事件的对数几率,其公式化简后,就是著名的Sigmoid函数。逻辑回归通常被用于处理二分类问题,但逻辑回归也可以做多分类,就是Softmax。

from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score

cancer = load_breast_cancer()
x = cancer.data
y = cancer.target

# 默认参数,L2惩罚项
LR_ = LogisticRegression()
score = cross_val_score(LR_, x, y, cv=10).mean()
print(score) #0.943

# 改为L1惩罚项
LR_1 = LogisticRegression(penalty='l1', solver='liblinear')
score = cross_val_score(LR_1, x, y, cv=10).mean()
print(score) #0.950

本文为 陈华 原创,欢迎转载,但请注明出处:http://edu.ichenhua.cn/read/279