【发布时间】:2018-08-18 23:32:28
【问题描述】:
在最简单的线性回归示例中存在问题。在输出处,系数为零,我做错了什么?感谢您的帮助。
import sklearn.linear_model as lm
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
x = [25,50,75,100]
y = [10.5,17,23.25,29]
pred = [27,41,22,33]
df = pd.DataFrame({'x':x, 'y':y, 'pred':pred})
x = df['x'].values.reshape(1,-1)
y = df['y'].values.reshape(1,-1)
pred = df['pred'].values.reshape(1,-1)
plt.scatter(x,y,color='black')
clf = lm.LinearRegression(fit_intercept =True)
clf.fit(x,y)
m=clf.coef_[0]
b=clf.intercept_
print("slope=",m, "intercept=",b)
输出:
slope= [ 0. 0. 0. 0.] intercept= [ 10.5 17. 23.25 29. ]
【问题讨论】:
标签: python pandas scikit-learn regression linear-regression