R에서 제공하는 Carseats 데이터 세트의 잔차를 교정하려고합니다. 임의의 포레스트로 시작하여 lamda = 0.1 인 지원 벡터 기계로 잔차를 수정 한 다음 사용하여 잔차를 수정합니다. 람다 = 0.1 인 KNN. 각 단계에서 5 배 CV를 사용하여 임의의 포레스트에 대한 매개 변수 mtry (3,5,10), svm의 감마 (0.01, .1,1,10) 및 k (1,5,10, 20). 나는 이것에 아주 새롭, 나는 문제를 시도했다, 그러나 나는 나가이 권리의 무엇이든을 한 경우에 정직하게 모른다. 여기에 내가 무엇을 가지고 있습니다 :R : 잔차 수정
set.seed (1)
##Random forest
#mtry=3
rf3 <- randomForest(Sales ~ .,
data = Carseats, mtry = 3, ntree = 500,
importance = TRUE)
#mtry=5
rf5 <- randomForest(Sales ~ .,
data = Carseats, mtry = 5, ntree = 500,
importance = TRUE)
#mtry=10
rf10 <- randomForest(Sales ~ .,
data = Carseats, mtry = 10, ntree = 500,
importance = TRUE)
#cross validation to pick best mtry -- am getting an error
library(tree)
cv.carseats = rfcv(trainx=Carseats[,-11], trainy=Carseats[,-11],cv.fold=5)
cv.carseats
##SVM
library(e1071)
f = svm(Sales~.,data=Carseats)
#gamma = 0.01
svm(Sales~., data=Carseats, type = NULL, kernel = "polynomial", degree = 3,
gamma = if (is.vector(x)) .01
else 1/ncol(x),
coef0 = 0, cost = 1)
#gamma = 0.1
svm(Sales~., data=Carseats, type = NULL, kernel = "polynomial", degree = 3,
gamma = if (is.vector(x)) 0.1
else 1/ncol(x),
coef0 = 0, cost = 1)
#gamma = 1
svm(Sales~., data=Carseats, type = NULL, kernel = "polynomial", degree = 3,
gamma = if (is.vector(x)) 1
else 1/ncol(x),
coef0 = 0, cost = 1)
#gamma = 10
svm(Sales~., data=Carseats, type = NULL, kernel = "polynomial", degree = 3,
gamma = if (is.vector(x)) 10
else 1/ncol(x),
coef0 = 0, cost = 1)
#cross validation to pick best gamma
tune.out=tune(svm,Sales~.,data=Carseats,kernel ="polynomial",
ranges =list(cost=c(0.01,0.1,1,10)))
모든 의견을 감사드립니다!
고맙습니다. 교차 인증을받지 못했습니다. – mapleleaf