Plot linear model in 3d with Matplotlib

前端 未结 2 1399
自闭症患者
自闭症患者 2020-12-09 07:07

I\'m trying to create a 3d plot of a linear model fit for a data set. I was able to do this relatively easily in R, but I\'m really struggling to do the same in Python. Here

2条回答
  •  感情败类
    2020-12-09 07:30

    You were correct in assuming that plot_surface wants a meshgrid of coordinates to work with, but predict wants a data structure like the one you fitted with (the "exog").

    exog = pd.core.frame.DataFrame({'TV':xx.ravel(),'Radio':yy.ravel()})
    out = fit.predict(exog=exog)
    ax.plot_surface(xx, yy, out.reshape(xx.shape), color='None')
    

提交回复
热议问题