2017-01-30 110 views
0

我在火花的虹膜数据上构建了一个简单的随机森林模型,我希望有一些精度测量的方法。SparkR中的测量精度

我想到了一个简单的列匹配的选项也一样,但是这并不工作

代码:

library("SparkR") 

sc = sparkR.session("local[*]") 

iris_data <- as.DataFrame(iris) 

train <- sample(iris_data, withReplacement=FALSE, fraction=0.5, seed=42) 
test <- except(iris_data, train) 


model_rf <- spark.randomForest(train, Species ~., "classification", numTrees = 10) 

summary(model_rf) 

问题:

predictions <- predict(model_rf, test) 

total_rows <- NROW(test) 

predictions$correct <- (test$Species == test$prediction) 

accuracy <- correct/total_rows 

print(accuracy) 

错误:

Error in column(callJMethod([email protected], "col", c)) : 

P.S: 使用数据砖头运行火花,不介意在本地运行的是

回答

0

所以这是我做的,

total_rows <- NROW(test) 

predictions$result <- ifelse((predictions$Species == predictions$prediction), 
           "TRUE", "FALSE") 

correct <- NROW(predictions[predictions$result == "TRUE",]) 

accuracy <- correct/total_rows 

cat(accuracy, "%")