-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathSVR.R
29 lines (24 loc) · 886 Bytes
/
SVR.R
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
# Support Vector Regression
## Setting the Working Directory
setwd('./Machine Learning A-Z/Part 2 - Regression/Section 7 - Support Vector Regression (SVR)')
# Importing the dataset
dataset = read.csv('Position_Salaries.csv')
dataset = dataset[2:3]
# Fitting the SVR Model to the dataset
library(e1071)
regressor = svm(formula = Salary ~ .,
data= dataset,
type= 'eps-regression')
# Predicting a new result
y_pred = predict(regressor, data.frame(Level = 6.5))
# Visualising the SVR Model results
# install.packages('ggplot2')
library(ggplot2)
ggplot() +
geom_point(aes(x = dataset$Level, y = dataset$Salary),
colour = 'red') +
geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = dataset)),
colour = 'blue') +
ggtitle('Truth or Bluff (SVR)') +
xlab('Level') +
ylab('Salary')