-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSupport_Vector_Regression.py
185 lines (74 loc) · 1.51 KB
/
Support_Vector_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
# coding: utf-8
# In[3]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.axes as ax
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from sklearn.svm import SVR
# In[14]:
from sklearn.datasets import load_boston
boston_data=load_boston()
boston_data
# In[8]:
data=pd.DataFrame(boston_data.data, columns=boston_data.feature_names)
# In[9]:
boston_data.feature_names
# In[10]:
data.head()
# In[11]:
data['MEDV']=boston_data.target
# In[12]:
data.head()
# In[15]:
data.info()#less entries
# In[16]:
data.describe()
# In[17]:
data.isnull().sum()
# In[18]:
x=data.drop(['MEDV'], axis=1)
y=data['MEDV']
# In[19]:
x.head()
# In[20]:
y.head()
# In[21]:
#scaling
sc_x=StandardScaler()
x=sc_x.fit_transform(x)
# In[22]:
x#range -1 to 1
# In[23]:
#split
xtrain,xtest,ytrain,ytest= train_test_split(x,y,test_size=0.2,random_state=0)
# In[24]:
xtrain.shape
# In[25]:
xtest.shape
# In[26]:
ytrain.shape
# In[29]:
ytest.shape
# In[30]:
#svr training odel
svr=SVR(kernel='rbf')#kernel selection hit and trial
svr.fit(xtrain,ytrain)
# In[32]:
#prediction
ypredict=svr.predict(xtest)
# In[34]:
ypredict
# In[35]:
ytest.head()
# In[38]:
#erroe
from sklearn.metrics import mean_squared_error
error=mean_squared_error(ypredict,ytest)
# In[39]:
error
# In[ ]:
#data not sufficient dataset too small