Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
随机森林模型的RMSE误差_R_Machine Learning_Random Forest_Rpart - Fatal编程技术网

随机森林模型的RMSE误差

随机森林模型的RMSE误差,r,machine-learning,random-forest,rpart,R,Machine Learning,Random Forest,Rpart,我试图训练一个随机森林模型,但我得到了以下错误。分类模型是否需要使用不同的设置来解决RMSE问题?我试着把“好”转换成一个因子,但这又带来了一个新的错误 错误: Error in train.default(x, y, weights = w, ...) : Metric RMSE not applicable for classification models 5 stop(paste("Metric", metric, "not applicable for classificati

我试图训练一个随机森林模型,但我得到了以下错误。分类模型是否需要使用不同的设置来解决RMSE问题?我试着把“好”转换成一个因子,但这又带来了一个新的错误

错误:

Error in train.default(x, y, weights = w, ...) : 
  Metric RMSE not applicable for classification models 
5 stop(paste("Metric", metric, "not applicable for classification models")) 
4 train.default(x, y, weights = w, ...) 
3 train(x, y, weights = w, ...) 
2 train.formula(good ~ ., data = train, method = "rf", trControl = trainControl(method = "cv", 
    5), ntree = 251) 
1 train(like ~ ., data = train, method = "rf", trControl = trainControl(method = "cv", 
    5), ntree = 251) 
下面是我用来训练模型的代码。我试图根据变量1-3中的值将数据集中的记录分类为“良好”

代码:


将好的东西转化为一个因素似乎可以解决问题。数据集中的所有变量的值都是TRUE或FALSE,并且都是字符类型。那么,在这种情况下,为什么随机林默认为回归而不是分类器呢

解决此问题的代码:

SampleTestData$good = as.factor(SampleTestData$good)
structure(list(good = c("True", "True", "True", "False", "False", 
"True", "True", "True", "True", "False", "True", "True", "True", 
"True", "False", "False", "False", "True", "False", "False", 
"True", "False", "True", "False", "True", "False", "True", "True", 
"False", "False", "True", "True", "False", "True", "True", "True", 
"True", "False", "False", "False", "False", "True", "False", 
"True", "True", "True", "False", "True", "False", "True", "False", 
"True", "True", "True", "False", "False", "True", "False", "True"
), variable1 = c("TRUE", "TRUE", "TRUE", "TRUE", 
"FALSE", "TRUE", "FALSE", "TRUE", "TRUE", "FALSE", "FALSE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "FALSE", "TRUE", "FALSE", "TRUE", 
"TRUE", "FALSE", "TRUE", "TRUE", "TRUE", "FALSE", "FALSE", "FALSE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "FALSE", "FALSE", 
"TRUE", "TRUE", "TRUE", "FALSE", "TRUE", "TRUE", "FALSE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "FALSE", "TRUE"), variable2 = c("TRUE", 
"TRUE", "TRUE", "TRUE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", 
"FALSE", "TRUE", "TRUE", "TRUE", "FALSE", "TRUE", "TRUE", "FALSE", 
"TRUE", "FALSE", "TRUE", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", 
"FALSE", "FALSE", "FALSE", "TRUE", "TRUE", "FALSE", "TRUE", "TRUE", 
"TRUE", "TRUE", "FALSE", "FALSE", "TRUE", "TRUE", "FALSE", "FALSE", 
"TRUE", "FALSE", "FALSE", "FALSE", "FALSE", "TRUE", "FALSE", 
"TRUE", "TRUE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"FALSE", "FALSE", "TRUE"), variable3 = c("FALSE", "FALSE", 
"FALSE", "FALSE", "FALSE", "FALSE", "TRUE", "FALSE", "FALSE", 
"FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", 
"FALSE", "TRUE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", 
"FALSE", "TRUE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", 
"FALSE", "TRUE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", 
"FALSE", "FALSE", "FALSE", "FALSE", "TRUE", "FALSE", "FALSE", 
"FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "TRUE", "FALSE", 
"TRUE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", 
"TRUE")), .Names = c("good", "variable1", "variable2", 
"variable3"), class = "data.frame", row.names = c(5078L, 
5087L, 5366L, 5568L, 7017L, 8123L, 8145L, 8525L, 11777L, 12355L, 
12586L, 12675L, 14912L, 15503L, 15530L, 15533L, 15598L, 15634L, 
15749L, 15842L, 16216L, 16718L, 16744L, 16792L, 17928L, 20351L, 
20417L, 21083L, 22382L, 23698L, 23807L, 23879L, 23900L, 30431L, 
30897L, 31084L, 31803L, 32007L, 32806L, 37487L, 37656L, 38284L, 
38291L, 38471L, 38786L, 40303L, 40724L, 41222L, 41248L, 41837L, 
42994L, 44423L, 45216L, 46233L, 47012L, 50446L, 52429L, 53197L, 
54590L))
SampleTestData$good = as.factor(SampleTestData$good)