Python 3线性回归问题

时间:2018-08-16 10:18:20

标签: python-3.x scikit-learn linear-regression

我正在使用sklearn(在python3.7上)进行简单的线性回归,但是intercept和fit comand给我相同的结果。 这是我的代码:

df = pd.DataFrame({'stud': [1,2,3,4,5,6,4,1,2,1,3],'red':[12000,23000,35000,47000,55000,67000,43000,15000, 25000,15000,31500]})
df
mat = np.matrix(df)
x = mat[:,1]
y = mat[:,0]
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr

lr.fit(x,y)
lr.intercept_ 

最后一条命令给了我以下结果:

array([-0.26514558])

我在预测comand上输入的每个值都会给我相同的结果

lr.predict(5)
lr.predict(5)
array([[-0.26467182]])

有人可以帮助我吗?

0 个答案:

没有答案
相关问题