def build_model(y, x, add_constant=True):
'''
Build a linear regression model from the provided data
Provided:
y: a series or single column dataframe holding our solution vector for linear regression
x: a dataframe that runs parallel to y, with all the features for our linear regression
add_constant: a boolean, if true it will add a constant row to our provided x data. Otherwise
this method assumes you've done-so already, or do not want one for some good reason
Return: a linear regression model from StatsModels and the data which was used to train the model.
If add_constant was true this will be a new dataframe, otherwise it will be x
'''
if add_constant:
x = sm.add_constant(x)
model = sm.OLS(y, x).fit()
return (model, x)
balance_preditctor.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录