如何使用python和statsmodels OLS函数绘制OLS模型?
这些功能的例子:
import statsmodels.api as sm
basic_ols = sm.OLS(regions['education'],regions[['income','life_ex',
'inf_mortality']],missing='drop').fit()
import statsmodels.formula.api as smf
formula_ols = smf.ols('MHDI_income ~ MHDI_education + MHDI_life_ex + C(locale)', data=MAs).fit()
我可以使用matplotlib或seaborn库绘制函数的散点图:
fig, ax = plt.subplots(figsize=(8,6))
ax.plot(x, y, 'o', label="data") # x and y are independent and dependent variables from a linear OLS regression
# plot x and y vars on a scatter plot
plt.scatter(cities.education, cities.income, alpha=0.66)
Here is an example of the plots I would like to produce,但我想使用多元回归的结果绘制Y变量运动的预测。
当使用多个x值时,该页面上的代码不起作用(值数组,例如我从我的" cities" dataframe中调用的3列)。
任何人都知道如何做到这一点? 干杯!