svm

 data(iris)

iris <- iris[,-c(5)]

library(rminer) 

model <- fit(Sepal.Length~.,data=iris,model="svm",

             kpar=list(sigma=0.1),C=1)

svm <- Importance(model,iris,measure="AAD")

svm$imp

par(mfrow=c(1,3))

boxplot(iris$Sepal.Width)$out

boxplot(iris$Petal.Length)$out

boxplot(iris$Petal.Width)$out

#因為離群值不多,所以先不轉

n <- nrow(iris)

set.seed(1117)

subiris <- sample(seq_len(n), size = round(0.7 * n))

traindata <- iris[subiris,]

testdata <- iris[ - subiris,]


library(e1071)

tune.model <- tune.svm(Sepal.Length~.,data=traindata,type="eps-regression",kernel="radial",

                       range=list(cost = 2^c(-8,-4,-2,0), epsilon = seq(0,10,0.1)))

tune.model$best.model #挑 lowest MSE 

model <- svm(Sepal.Length~.,data=traindata,type="eps-regression",kernel="radial",cost=1,epsilon=0.1,gamma=0.3333333)

future <- predict(model,testdata)

future <- as.data.frame(future)

final <- cbind(future,testdata)

library(dplyr)

final <- mutate(final,mape=abs(future-Sepal.Length)/Sepal.Length)

mean(final$mape)

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理