【发布时间】:2021-03-29 12:08:11
【问题描述】:
我一直在尝试为多变量回归绘制回归线,ENGINESIZE 和 FUELCONSUMPTION_CITY 都是自变量,CO2EMISSION 是因变量。
我试图绘制一条回归线,但无论如何,我无法绘制它,因为它一直向我显示相同的错误。
下面是我的代码:-
z_cord = regr.coef_[0][0]*train_engine[['ENGINESIZE']]
z_cod = regr.coef_[0][1]*train_engine[['FUELCONSUMPTION_CITY']]
s = y_cord.add(y_cod, fill_value=0)
l = []
for index, row in s.iterrows():
l.append(row['ENGINESIZE']+row['FUELCONSUMPTION_CITY'] + regr.intercept_)
z = pd.DataFrame(l,columns=['CO2EMISSION'])
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(data[['ENGINESIZE']],data[['FUELCONSUMPTION_CITY']],co2_data)
x = train_engine[['ENGINESIZE']]
y = train_engine[['FUELCONSUMPTION_CITY']]
ax.plot3D(x,y,z,color='red')
plt.show()
每次我运行它都会给我这些错误
ValueError: input operand has more dimensions than allowed by the axis remapping
AttributeError: 'Line3D' object has no attribute '_verts3d'
当我评论ax.plot3D(x,y,z,color='red')线时绘制散点图。
我不知道我哪里出错了,我们将不胜感激。
【问题讨论】:
标签: python matplotlib scikit-learn linear-regression