machine-learning - sklearn LinearRegression,为什么模型只返回一个系数?

标签 machine-learning scikit-learn linear-regression

我正在一个简单的数据集上尝试 scikit-learn LinearRegression 模型(来自 Andrew NG coursera 类(class),我并不重要,请查看图表以供引用)

这是我的脚本

import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

dataset = np.loadtxt('../mlclass-ex1-008/mlclass-ex1/ex1data1.txt', delimiter=',')
X = dataset[:, 0]
Y = dataset[:, 1]


plt.figure()
plt.ylabel('Profit in $10,000s')
plt.xlabel('Population of City in 10,000s')
plt.grid()
plt.plot(X, Y, 'rx')

model = LinearRegression()
model.fit(X[:, np.newaxis], Y)

plt.plot(X, model.predict(X[:, np.newaxis]), color='blue', linewidth=3)

print('Coefficients: \n', model.coef_)

plt.show()

我的问题是: 我希望这个线性模型有 2 个系数:截距项和 x 系数,为什么我只得到一个?

enter image description here

最佳答案

哎呀

我没有注意到截距是模型的一个单独的属性!

print('Intercept: \n', model.intercept_)

查看文档here

intercept_ : array

Independent term in the linear model.

关于machine-learning - sklearn LinearRegression,为什么模型只返回一个系数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29703028/

相关文章:

python - pickle .load : ImportError: No module named k_means_

python - 具有多次重复的 scikit-learn GridSearchCV

python - statsmodels OLS 中的 t 值和标准误差使用哪个公式

python - 使用 TensorFlow 的梯度下降比基本的 Python 实现慢得多,为什么?

machine-learning - 如何在 Movidius 上测试自定义创建的 tensorflow 模型?

machine-learning - Weka 用于评估连续值熵的 InfoGainAttributeEval 公式是什么?

python - 如何在keras中记录每批处理的val_loss和loss

python - 如何删除Python中缺失值过多的列

python - 使用 python 使用 sklearn 进行线性回归

machine-learning - 华纳(AVE 套件): eliminate "connected" terms from frequent patterns