2017-03-21 7 views
0

그래서 모델을 훈련시키고 무작위 포리스트 회귀를 사용하여 테스트하려고합니다. 내 응답 변수는 숫자이고 숫자와 문자가 혼합 된 23 개의 다른 변수가 있습니다.랜덤 포레스트 (회귀)에 대한 캐럿 패키지 사용 중 오류

library(e1071) 
library(dplyr) 
library(class) 
library(caret) 
library(kernlab) 

data=read.csv(choose.files()) 


set.seed(1) 
mydata=data 
n=dim(mydata)[1] 
p=dim(mydata)[2]-1 
x=mydata[,-3] 
y=mydata[,3] 

n_train=35 
n_test=9 

random_order=sample(n) 
test_index=random_order[1:n_test] 
train_index=random_order[-(1:n_test)] 
y_train=y[train_index] 
y_test=y[test_index] 
x_train=x[train_index,] 
x_test=x[test_index,] 

traindata=data.frame(x=x_train,y=(y_train)) 
testdata = data.frame(x=x_test,y=(y_test)) 

fitControl <- trainControl(## 10-fold CV 
    method = "repeatedcv",classProbs=TRUE, 
    number = 10, 
    ## repeated ten times 
    repeats = 10) 

set.seed(1) 
newrf=train(y ~ ., data = traindata , method = "rf", 
      trControl = fitControl) 

newrf 
bestmodel_rf= newrf$finalModel 
ypredcaret=predict(bestmodel_rf, newdata = testdata) 
table(predict=ypredcaret, truth=y_test) 
plot(newrf) 
bestmodel_rf 

나는 다음과 같은 오류가 점점 오전 :

경고 메시지 : train.default에서 (X, Y, 무게 = w, ...) : 를 나는 다음과 같은 코드 블록을 사용하고 있습니다 회귀 경고 메시지 클래스 확률을 계산 cannnot : train.default에서 를 (X, Y는, 가중치 = ... W) : 회귀에 대한 클래스 확률을 계산 cannnot

답변

2

당신은 산업사하는 trainControl에서 classProbs=T 지정한 분류 모델 (응답 변수가 개별 클래스 레이블로 구성되는 경우)에 대해 클래스 확률이 계산되어야합니다. 그러나이 인수 설정은 숫자 응답 변수 (회귀 모델이 훈련됨을 나타냄)와 충돌하므로 회귀에 대한 클래스 확률을 계산할 수 없다는 오류 메시지가 나타납니다.

설명과 숫자 응답 변수가 회귀 문제임을 나타내므로 코드에서 classProbs=T (기본 설정은 classProbs=F)을 제거하면 발생하는 오류를 해결해야합니다.