线性回归是最常见的统计建模方法之一,本节将向大家介绍 Scikit-Learn 中线性回归工具的使用方法,以及一些常用的操作技巧。
首先,我们导入需要用到的其他工具库,并对构建的示例数据进行展示:


可以看到,这些随机样本的两个特征在二维空间中表现为较明显的正相关关系:
通过导入 Scikit-Learn 的 LinearRegression 函数,我们可以很轻松地构建一个线性回归模型,模型的构建过程及拟合效果如下:


我们可以通过模型对象的 coef_ 和 intercept_ 属性查看回归曲线的斜率与截距:

当存在多个自变量时,线性回归模型将会默认地拟合估计截距与自变量相对应的回归系数数组:

在前几节中我们曾经谈到过, Scikit-Learn 中的 PolynomialFeatures 函数可以帮助我们生成自变量 x 的幂,从而方便我们构建多项式线性回归:

未完待续:课程内容较多,请复制链接通过电脑学习,获得最佳学习效果。 http://datacademy.io/lesson/141
更多课程和文章尽在微信号:「datartisan数据工匠」

网友评论