Python 使用matplotlib在三维中将数据打印为线性模型

Python 使用matplotlib在三维中将数据打印为线性模型,python,pandas,matplotlib,linear-regression,Python,Pandas,Matplotlib,Linear Regression,我想在下面的链接中绘制一些数据 如果OLS公式中的“电视和广播”不止一个,而我只想用“销售”来描绘这两个,我该怎么办?因为如果我喜欢下面的代码(链接),它会向我显示一个错误,其他代码没有定义(电视和广播除外) 谢谢你的帮助 以下是链接的代码: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np import pandas as pd import statsmode

我想在下面的链接中绘制一些数据

如果OLS公式中的“电视和广播”不止一个,而我只想用“销售”来描绘这两个,我该怎么办?因为如果我喜欢下面的代码(链接),它会向我显示一个错误,其他代码没有定义(电视和广播除外)

谢谢你的帮助

以下是链接的代码:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import statsmodels.formula.api as sm
from matplotlib import cm

csv = pd.read_csv('http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv', index_col=0)
model = sm.ols(formula='Sales ~ TV + Radio', data = csv)
fit = model.fit()

fit.summary()

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x_surf = np.arange(0, 350, 20)                # generate a mesh
y_surf = np.arange(0, 60, 4)
x_surf, y_surf = np.meshgrid(x_surf, y_surf)

exog = pd.core.frame.DataFrame({'TV': x_surf.ravel(), 'Radio': y_surf.ravel()})
out = fit.predict(exog = exog)
ax.plot_surface(x_surf, y_surf,
                out.reshape(x_surf.shape),
                rstride=1,
                cstride=1,
                color='None',
                alpha = 0.4)

ax.scatter(csv['TV'], csv['Radio'], csv['Sales'],
           c='blue',
           marker='o',
           alpha=1)

ax.set_xlabel('TV')
ax.set_ylabel('Radio')
ax.set_zlabel('Sales')

plt.show()

请发布代码示例,说明您尝试了什么,哪些不起作用,以及我提到的didas,通过这段代码,我可以绘制一些数据,但我也希望OLS公式中的一个或多个附加参数具有相同的数据。所以我也做了同样的事情,这是可以的,但只是公式中有更多的参数,我得到一个错误,这些额外的参数没有定义。所以我没有更多的代码样本。。