SVR 之R语言样例

目前我自己对SVR的理解就是在一定范围内提高模型精度

SVR 之R语言样例_第1张图片
SVR实例图

在SVR模式下用数据喂养模型

# Fitting SVR to the dataset

install.packages('e1071')

library(e1071)

regressor = svm(formula = Salary ~ .,

                              data = dataset,

                              type = 'eps-regression',

                              kernel = 'radial')

再预测下 6.5Level 的薪资

6.5Level 的薪资177861

再将数据可视化下

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')


SVR 之R语言样例_第2张图片
SVR Truth or Bluff

library(ggplot2)

x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1)   #数据颗粒化平滑些

ggplot() +

geom_point(aes(x = dataset$Level, y = dataset$Salary),

colour = 'red') +

geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))),

colour = 'blue') +

ggtitle('Truth or Bluff (SVR1)') +

xlab('Level') +

ylab('Salary')


SVR 之R语言样例_第3张图片
SVRI

你可能感兴趣的:(SVR 之R语言样例)