statsmodels 最小二乘法 线性回归

最近使用到了ols做线性回归,记录一下使用方法

首先是statsmodels,根据官网介绍,这是python里一个用于estimate statistical models 和 explore statistical data 的模块,经常做数据分析的小伙伴应该都不陌生

statsmodels is a Python module that provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests, and statistical data exploration. An extensive list of result statistics are available for each estimator. The results are tested against existing statistical packages to ensure that they are correct. 

然后是ols的方法,悉大的tutor给到了api 和 formula.api 两种建模方法,感觉直接用formula更省事些,毕竟自己做老容易忘记加intercept  >-<

方法一:statsmodels.api 做最小二乘法,需要自己添加intercept截距项

方法二:statsmodels.formula.api 通过自定formula和dataframe生成模型,无需添加截距项

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值