对于回归问题,线性模型预测的一般公式为:
y=w[0]*x[0]+w[1]*x[1]+............+w[p]*x[p]+b
这里的x[0]到x[p]表示的事单个数据点的特征,w和b是学习模型的参数,y是模型的预测结果。对于单一特征的数据集,公式:
y=w[0]*x[0]+b
这里的w[0]是斜率,b是y轴偏移。对于有更多特征的数据集,w包含沿每个特征坐标轴的斜率。
python
import mglearn.datasets
import matplotlib.pyplot as plt
mglearn.plots.plot_linear_regression_wave()
plt.show()


从w[0]可以看出,斜率应该在0.4左右。截距是指预测直线与y轴的交点,比0略小。