I am trying to use linear regression that takes two variables "Idade" and "LF" and tries to predict a third one, "DGAF". I'm trying to both do the scatterplot with the observations and the model prediction on the same graph. Bellow is the code I used (using Python).
X = df[["Idade","LF"]] y = df["DGAF"].values.reshape(len(df["DGAF"]),1) reg = LinearRegression() reg.fit(X, y) fig = plt.figure() ax = Axes3D(fig) ax.scatter(X['Idade'],X['LF'], y,s=10) x_pred = np.linspace(0,100,1000) y_pred = np.linspace(0,100,1000) xx_pred, yy_pred = np.meshgrid(x_pred, y_pred) model_viz = np.array([xx_pred.flatten(), yy_pred.flatten()]).T ax.set_xlabel('Years since oil change') ax.set_ylabel('LF') ax.set_zlabel('DGA Score') ax.plot(model_viz, model_viz, reg.predict(model_viz),color='red') plt.show()
I get this error:
ValueError: input operand has more dimensions than allowed by the axis remapping
I am able to do the scatterplot, the issue seems to be with plotting the prediction. How can I solve this?