python中线性回归LR函数参数

Tanisha ·
更新时间:2024-09-21
· 809 次阅读

LR工具
from sklearn.linear_model.logistic import LogisticRegression

参数: penalty,惩罚项,正则化参数,防止过拟合,l1或l2,默认为l2 C,正则化系数λ的倒数,float类型,默认为1.0 solver,损失函数优化方法,liblinear(默认),lbfgs, newton-cg,sag
random_state,随机数种子 max_iter,算法收敛的最大迭代次数,默认为100 tol=0.0001 : 优化算法停止条件,迭代前后函数差小于tol则终止 verbose=0 : 日志冗长度int:冗长度;0:不输出训练过程;1:偶尔输出;>1:对每个子模型都输出 n_jobs=1 : 并行数,int:个数;-1:跟CPU核数一致;1:默认值

常用方法:

fit(X, y, sample_weight=None)

fit_transform(X, y=None, **fit_params)

predict(X),用来预测样本,也就是分类 predict_proba(X),输出分类概率。返回每种类别的概率,按照分类类别顺序给出。

score(X, y, sample_weight=None),返回给定测试集合的平均准确率(mean accuracy)

模型参数配置:

model = LogisticRegression(max_iter=100, verbose=True, random_state=33, tol=1e-4 ) model.fit(X_train, y_train) predict = model.predict_proba(test)[:, 1] test['Attrition']=predict # 转化为二分类输出 test['Attrition']=test['Attrition'].map(lambda x:1 if x>=0.5 else 0) test[['Attrition']].to_csv('submit_lr.csv')
作者:Bug永流传



lr 参数 线性 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号