使用 scikit learn 在多元回归中访问 y 截距
Access y-intercept in multiple regression using scikitlearn
我遵循了这个 post 中接受的答案:
Multiple linear regression in Python
在评论中,提到了如何用常数项(y截距)拟合直线。我如何访问它?
拟合模型后,截距可用 model.intercept_
。这是一个例子:
# Example that should have intercept of 1
x = np.random.rand(10,3)
y = 1 + x.dot([1,2,3]) + 0.05 * np.random.rand(10)
lr.fit(x, y)
lr.coef_
>> array([ 1.01701958, 2.00951304, 3.00504058])
lr.intercept_
>> 0.99952789780697682
我遵循了这个 post 中接受的答案:
Multiple linear regression in Python
在评论中,提到了如何用常数项(y截距)拟合直线。我如何访问它?
拟合模型后,截距可用 model.intercept_
。这是一个例子:
# Example that should have intercept of 1
x = np.random.rand(10,3)
y = 1 + x.dot([1,2,3]) + 0.05 * np.random.rand(10)
lr.fit(x, y)
lr.coef_
>> array([ 1.01701958, 2.00951304, 3.00504058])
lr.intercept_
>> 0.99952789780697682