数据挖掘_R_Python_ML(2): Linear Regression vs SVR

> install.packages("e1071", dep = TRUE)

> library(e1071)

> x<-mydata[,1]

> y<-mydata[,2]

> svm.r=svm(y~x,mydata); svm.r

Call:

svm(formula = y ~ x, data = mydata)

Parameters:

SVM-Type: eps-regression

cost: 1

gamma: 1

epsilon: 0.1

> predictedY <- predict(svm.r, mydata)

> predictedY

1 2 3 4 5 6 7

3.968246 4.273861 5.133763 6.115467 7.000000 7.884533 8.866237

8 9

9.726139 10.031754

> plot(x,y)

> points(x,predictedY, col = "red")

> svm.r2=svm(y~x, kernel = "linear"); svm.r2

Call:

svm(formula = y ~ x, kernel = "linear")

Parameters:

SVM-Type: eps-regression

SVM-Kernel: linear

cost: 1

gamma: 1

epsilon: 0.1

Number of Support Vectors: 2

> predictedY2 <- predict(svm.r2, mydata)；predictedY2

1 2 3 4 5 6 7

3.273861 4.205396 5.136931 6.068465 7.000000 7.931535 8.863069

8 9

9.794604 10.726139

> svm.r3=svm(y~x, type = "nu-regression",kernel = "linear"); svm.r3

Call:

svm(formula = y ~ x, type = "nu-regression",kernel = "linear")

Parameters:

SVM-Type: nu-regression

SVM-Kernel: linear

cost: 1

gamma: 1

nu: 0.5

Number of Support Vectors: 2

> predictedY3 <- predict(svm.r3, mydata); predictedY3

1 2 3 4 5 6 7 8 9

3 4 5 6 7 8 9 10 11

svm.r3的结果和实际一致！我们再用可视化图形展示一下这个结果：

> points(x,predictedY2, col = "blue")

> points(x,predictedY3, col ="green")

> rmse <- function(error)

+ {

+ sqrt(mean(error^2))

+ }

>

> error2 <- svm.r2\$residuals; #same as mydata\$Y – predictedY3

> error2

1 2 3 4 5 6

-0.27386138 -0.20539603 -0.13693069 -0.06846534 0.00000000 0.06846534

7 8 9

0.13693069 0.20539603 0.27386138

> predictionRMSE2 <- rmse(error2); predictionRMSE2

[1] 0.1767768

> error3 <- svm.r3\$residuals; error3

1 2 3 4 5

-5.757728e-08 -5.027875e-08 -4.298022e-08 -3.568169e-08-2.838316e-08

6 7 8 9

-2.108464e-08 -1.378611e-08 -6.487580e-09 8.109495e-10

> predictionRMSE3 <- rmse(error3); predictionRMSE3

[1] 3.406945e-08

0 条评论

相关文章

?

388120

数据挖掘中的利器--XGBoost理论篇

XGBoost是各种数据挖掘或机器学习算法类比赛中每个团队都会使用且精度相对最好的算法之一（Deep Learning算法除外）。也就是说，对于刚转向机器学习领...

57190

37260

439120

40060

376130

381120

43790

详解数据挖掘与机器学习的区别与联系

0、为什么写这篇博文 　　最近有很多刚入门AI领域的小伙伴问我：数据挖掘与机器学习之间的区别与联系。为了不每次都给他们长篇大论的解释，故此在网上整理了一些资料，...

394110

410130