-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiple Linear Regression.py
101 lines (41 loc) · 1 KB
/
Multiple Linear Regression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
# coding: utf-8
# In[15]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# In[16]:
dataset = pd.read_csv('startups.csv')
x = dataset.iloc[:, :-1]
y = dataset.iloc[:, 4]
x
# In[6]:
y
# In[7]:
states=pd.get_dummies(x['State'], drop_first=True)
# In[8]:
x = x.drop('State',axis=1)
# In[9]:
x = pd.concat([x,states],axis=1)
# In[10]:
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state = 0)
# In[11]:
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(x_train, y_train)
# In[12]:
y_pred = regressor.predict(x_test)
# In[18]:
from sklearn.metrics import r2_score
score=r2_score(y_test,y_pred)
print(f'R2 score: {score}')
# In[14]:
plt.figure(figsize = (5, 5))
plt.scatter(y_test, y_pred)
plt.title('Actual vs Prdicted')
plt.xlabel('Actual')
plt.ylabel('Predicted')
# In[ ]:
# In[ ]:
# In[ ]: