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)
y_head = multiple_lr.predict(array)
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.
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). $\endgroup$