python - Plot linear model in 3d with Matplotlib -


I am 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 having difficulty in doing this in Python. Here I have done R:

3D plot

 : p> here What I have been doing in Python = pd.read_csv ('http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv', index_col = 0) model = sm.ols (formula = 'sales ~ Ft = model.fit () fit.summary () fig = plt.figure () ax = fig.add_subplot (111, projection = '3d') ax.scatter (csv [ ' Xvi, csv ['radio'], csv ['sale'], c = 'r', marker = 'o' xx, yy = np.meshgrid (csv ['tv'], csv ['radio' ]) # Not what I expected: (# ax.plot_surface (xx, yy, fit.fittedvalues) ax.set_xlabel ('TV') ax.set_ylabel ('radio') ax.set_zlabel ('sale') plt.show ( )  

What am I doing and what should I do instead?

Thank you.

You were right in handling that conspiracy _Serfes wants coordinates to work with a mashgrid, But predicts that you want a data structure like anyone who is fit with ("Exag").

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

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -