-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain linear .py
More file actions
100 lines (35 loc) · 917 Bytes
/
train linear .py
File metadata and controls
100 lines (35 loc) · 917 Bytes
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
98
99
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
# In[2]:
df = pd.read_csv("C:\\Users\\parag\\Desktop\\train.csv")
# In[3]:
df.head()
# In[6]:
correlation_values = df.select_dtypes(include=[np.number]).corr()
type(correlation_values)
# In[10]:
correlation_values[["Id", "SalePrice"]]
# In[11]:
X = df[["OverallQual", "TotalBsmtSF", "GrLivArea", "GarageArea"]]
# In[12]:
y = df['SalePrice']
# In[15]:
from sklearn.model_selection import train_test_split as tts
# In[16]:
X_train, X_test, y_train, y_test = tts(X, y, test_size= 0.3, random_state= 42)
# In[17]:
from sklearn.linear_model import LinearRegression
# In[19]:
reg = LinearRegression()
# In[20]:
reg.fit(X_train, y_train)
# In[21]:
y_pred = reg.predict(X_test)
# In[24]:
reg.score(X_test, y_test)
# In[25]:
from sklearn.metrics import r2_score
# In[26]:
r2_score(y_test, y_pred)