-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSupport Vector Regression.R
38 lines (26 loc) · 1.16 KB
/
Support Vector Regression.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
30
31
32
33
34
35
36
37
38
# -------------------------------------------------- Importing Data ------------------------------------------- #
dataset = read.csv("Position_Salaries.csv")
# Selecting particular columns
dataset = dataset[2:3]
# Level is the independent variable.
# Salary is the dependent variable.
# -------------------------------- Fitting Support Vector Regression to the dataset --------------------------- #
install.packages('e1071')
library(e1071)
reg = svm(Salary ~ ., data = dataset, type = "eps-regression")
summary(reg)
# -------------------------------- Predictiing a new result with Linear Regression ---------------------------- #
y_pred = predict(reg, data.frame(Level = 6.5))
y_pred
# ------------------------------- Visualising the Support Vector Regression results --------------------------- #
# Installing Package
install.packages("ggplot2")
library(ggplot2)
# Plotting
ggplot() +
geom_point(aes(x = dataset$Level, y = dataset$Salary),
colour = 'red') +
geom_line(aes(x = dataset$Level, y = predict(reg, newdata = dataset)),
colour = 'blue') +
ggtitle("Truth or Bluff (Support Vector Regression)") +
xlab("Level") + ylab("Salary")