2017-04-13 7 views
0

Rでrpartライブラリを使用して回帰ツリーを作成します!私は4つの独立変数と3つの独立した予測変数を持っています。すべてのVARSはrpart:confusionMatrixエラー(回帰木)

mydata="mydata.csv" 
library(caret) 
library("rpart") 
class1=read.csv(mydata,sep=";",dec=",") 
# rpart 
fit <- rpart(y1+y2+y3+y6~ ., method="anova",data=class1) 
set.seed(123) 
index <- sample(1:nrow(class1),round(0.75*nrow(class1))) 
train <- class1[index,] 
str(train) 
test <- class1[-index,] 
str(test) 
fit <- rpart(y1+y2+y3+y6~ ., method="anova",data=train) 
predict(fit) 
predicted.t=predict(fit) 

は、今私はconfusionMatrix()を使いたい(。すなわちメートルスケール)のスケールですが、私は

> confusionMatrix(predicted.t,test) 
Error in sort.list(y) : 'x' must be atomic for 'sort.list' 
Have you called 'sort' on a list? 

>

dput(class) 
structure(list(x1 = c(215L, 170L, 340L, 320L, 320L, 320L, 300L, 
305L, 345L, 300L, 340L, 220L, 320L, 220L, 300L, 300L, 300L, 215L, 
275L, 255L, 275L, 320L, 345L, 250L, 220L, 250L, 300L, 220L, 215L, 
300L, 255L, 345L, 350L, 305L, 320L, 215L, 215L, 300L, 220L, 255L, 
305L, 320L, 345L, 250L, 305L, 255L, 305L, 305L, 255L, 275L, 320L, 
340L, 250L, 300L, 305L, 320L, 250L, 300L, 215L, 250L, 220L, 220L, 
320L, 300L, 350L, 350L, 350L, 305L, 170L, 220L, 350L, 320L, 215L, 
305L, 255L, 170L, 340L, 300L, 300L, 255L, 300L, 320L, 275L, 275L, 

場合はエラーを得た

View(class) 
x1 x2 x3 y1 y2 y3 y6 
215 15,4 94 90 7 3 54,886501 
170 16 85 90 6 4 54,886501 
340 12,2 72 70 15 15 54,886501 
320 15,1 78 80 12 8 54,886501 
320 9,7 77 80 5 15 54,886501 
320 11,1 70 90 1 9 54,886501 
300 14,6 85 80 14 6 54,886501 
305 8,6 74 90 6 4 54,886501 
345 15 85 90 5 5 54,886501 
300 13,7 85 90 7 3 54,886501 
340 14,3 82 80 18 2 54,886501 
220 8,6 77 80 15 5 54,886501 
320 13,2 73 80 12 8 54,886501 
220 8,4 85 90 5 5 54,886501 
300 16 85 90 7 3 56,08118233 
300 8,4 72 90 7 3 54,886501 
300 13,7 77 90 7 3 54,886501 
215 15,1 77 90 6 4 56,08118233 
275 12,2 94 70 15 15 56,08118233 
255 16 85 80 12 8 54,886501 
275 11,1 94 80 5 15 54,886501 

どのようにエラーを修正するには?

+0

'class'はRの基本関数であり、あなたのデータセットは関数定義で上書きされることに注意してください。ランダム化されたサンプリングを使用すると、再現性を保証するためにxを好きな数として' set.seed(x)結果。 – OdeToMyFiddle

+0

こんにちは、私は自分の投稿を編集しました。ここで.csv形式のmydata。 [link](https://www.sendspace.com/file/ws44ig) –

答えて

0

ここ

u = union(round(predicted.t),test$y6) 
t = table(factor(round(predicted.t), u), factor(test$y6, u)) 
confusionMatrix(t) 

ので、行列作品が答えます。