Python 在多元线性回归模型中如何预测y值?
我有一个OLS模型来估计房价Python 在多元线性回归模型中如何预测y值?,python,Python,我有一个OLS模型来估计房价 import numpy as np import statsmodels.formula.api as sm model = sm.ols('np.log(price) ~ np.log(lotsize) + np.log(sqrft) + bdrms', data = df).fit() 我想将以下beta值插入预测y(价格)的估计方程中: lotsize=20000,sqrft=2500,bdrms=4 在R中有一种优雅的方法可以实现这一点,我正试图在Py
import numpy as np
import statsmodels.formula.api as sm
model = sm.ols('np.log(price) ~ np.log(lotsize) + np.log(sqrft) + bdrms', data = df).fit()
我想将以下beta值插入预测y(价格)的估计方程中:
lotsize=20000,sqrft=2500,bdrms=4
在R中有一种优雅的方法可以实现这一点,我正试图在Python中复制这一点,但迄今为止运气不佳:
我的目标是在Python代码中实现类似的功能,以预测y值
predictY <- predict.lm(linearModel, data.frame(lotsize = c(20000), sqrft = c(2500), bdrms = c(4)))
exp(predictY)
predictY谢谢大家。看起来最好的方法是这样做,以防有人无意中发现我的帖子:
p = model.get_prediction(pd.DataFrame([{"lotsize":20000,"sqrft": 2500, "bdrms": 4}]))
p.summary_frame()