在用以下代码建立逻辑回归模型的时候
lr = LogisticRegression(C = c_param, penalty = ‘l1’)
LogisticRegression的参数如下:
LogisticRegression(C=0.01, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='auto', n_jobs=None, penalty='l1',
random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
warm_start=False)
我们看solver参数,这个参数定义的是分类器,‘newton-cg’,‘sag’和‘lbfgs’等solvers仅支持‘L2’regularization,‘liblinear’ solver同时支持‘L1’、‘L2’regularization,若dual=Ture,则仅支持L2 penalty。
决定惩罚项选择的有2个参数:dual和solver,如果要选L1范数,dual必须是False,solver必须是liblinear
因此,我们只需将solver='liblinear’参数添加进去即可
lr = LogisticRegression(C = c_param, penalty = ‘l1’,solver=‘liblinear’)