开始使用免费开始使用

拟合逻辑回归模型

研究某大学中学习时长与某次测试结果之间关系的团队向您提供了一份数据集,包含学生的学习小时数,以及他们是否通过测试。现在请您拟合一个模型来预测未来的成绩。

数据已存放在变量 hours_of_studyoutcomes 中。请使用这些数据拟合一个 LogisticRegression 模型。为方便起见,已导入 numpy 并命名为 np

本练习是课程的一部分

Python 概率基础

查看课程

练习说明

  • sklearn.linear_model 导入 LogisticRegression
  • 使用 LogisticRegression(C=1e9) 创建模型。
  • 将数据传入 model.fit() 方法。
  • 为每个参数创建变量,从模型中赋值,并打印参数 beta1beta0

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import LogisticRegression
from sklearn.linear_model import ____

# sklearn logistic model
model = ____(C=1e9)
model.____(____, ____)

# Get parameters
beta1 = model.coef_[0][0]
beta0 = model.intercept_[0]

# Print parameters
print(____, ____)
编辑并运行代码