# Plotting in Multiple Linear Regression in Python 3

So I'm working on linear regression. So far I've managed to plot in linear regression, but currently I'm on Multiple Linear Regression and I couldn't manage to plot it, I can get some results if I enter the values manually, but I couldn't manage to plot it. Below is my code block and dataset and error, what can i change to plot it?

Dataset:

deneyim maas    yas
0.5 2500    22
0   2250    21
1   2750    23
5   8000    25
8   9000    28
4   6900    23
15  20000   35
7   8500    29
3   6000    22
2   3500    23
12  15000   32
10  13000   30
14  18000   34
6   7500    27


Code block:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LinearRegression

dataset = pd.read_csv("multiple-linear-regression-dataset.csv",sep = ";")

x = dataset.iloc[:,[0,2]].values
y = dataset.maas.values.reshape(-1,1)

multiple_lr = LinearRegression()
multiple_lr.fit(x,y)

b0 = multiple_lr.intercept_
b1 = multiple_lr.coef_
b2 = b1

multiple_lr.predict(np.array([[10,35],[5,35]]))

array = np.array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]).reshape(-1,1)

plt.scatter(x,y)
plt.plot(array, y_head, color = "red")
plt.show()


It says ValueError: shapes (16,1) and (2,1) not aligned: 1 (dim 1) != 2 (dim 0) when I try to compile it.

• What does this code actually give then? Can you post a screenshot of the result? Or is there a bug? The plotting part seems ok to me, but is hard to test without having that dataset. – n1k31t4 Aug 13 '18 at 13:06
• It seems like X has two features (iloc[:, [0, 2]]). But then you try to use the regression on that [0, 1, ..., 15] array that has only one feature. And even after you get the predictions, the visualization will have to be 3D (because of the two Xs plus the Y). – Mephy Aug 13 '18 at 13:34
• I've tried a 3D plot using mplot3D for a similar problem. Check this out: medium.com/@anupriyaincbe/… – Anupriya Thirumurthy Oct 11 '18 at 19:21