Skip to content

Commit 965f959

Browse files
authored
Add files via upload
1 parent f0b241c commit 965f959

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# In[61]:
5+
6+
7+
#import libabry
8+
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
import pandas as pd
12+
from sklearn.preprocessing import StandardScaler
13+
from sklearn.svm import SVR
14+
15+
16+
# In[62]:
17+
18+
19+
#read dataset
20+
dataset = pd.read_csv('~/Downloads/Data Science/data set/Position_Salaries.csv')
21+
X = pd.DataFrame(dataset, columns = ['Gender', 'Age'])
22+
y = pd.DataFrame(dataset, columns = ['EstimatedSalary'])
23+
24+
25+
# In[68]:
26+
27+
28+
#Feature Scaling
29+
sc_X = StandardScaler()
30+
sc_y = StandardScaler()
31+
X = sc_X.fit_transform(X)
32+
y = sc_y.fit_transform(y)
33+
34+
35+
# In[69]:
36+
37+
38+
#build model
39+
regressor = SVR(kernel = 'rbf')
40+
regressor.fit(X, y)
41+
42+
43+
# In[ ]:
44+
45+
46+
#predicte new value
47+
48+
y_pred = regressor.predict(6.5)
49+
y_pred = sc_y.inverse_transform(y_pred)
50+
view raw
51+
52+
53+
# In[70]:
54+
55+
56+
# Visualize SVR
57+
X_grid = np.arange(min(X), max(X), 0.01) #this step required because data is feature scaled.
58+
X_grid = X_grid.reshape((len(X_grid), 1))
59+
plt.scatter(X, y, color = 'red')
60+
plt.plot(X_grid, regressor.predict(X_grid), color = 'blue')
61+
plt.title('Truth or Bluff (SVR)')
62+
plt.xlabel('Position level')
63+
plt.ylabel('Salary')
64+
plt.show()
65+
66+
67+
# In[ ]:
68+
69+
70+
71+

0 commit comments

Comments
 (0)