如何评估R中的多项分类模型?

时间:2017-04-22 07:59:34

标签: r precision h2o auc

我目前正在尝试建立一个多级预测模型来预测26个英文字母中的字母。我目前使用ANN,SVM,Ensemble和nB构建了一些模型。但我坚持评估这些模型的准确性。虽然混淆矩阵向我展示了字母顺序的真假预测,但我只能得到每个模型的整体精确度。有没有办法评估模型的准确性,类似于二项分类的ROC和AUC值。 注意:我目前正在使用H2o包运行模型,因为它为我节省了更多时间。

1 个答案:

答案 0 :(得分:2)

在H2O中训练模型后,如果您只是执行:print(fit),它将显示该模型类型的所有可用指标。对于多类,我建议h2o.mean_per_class_error()

虹膜数据集上的R代码示例:

library(h2o)
h2o.init(nthreads = -1)

data(iris)
fit <- h2o.naiveBayes(x = 1:4, 
                      y = 5, 
                      training_frame = as.h2o(iris), 
                      nfolds = 5)

获得模型后,我们可以使用h2o.performance()函数评估模型性能,以查看所有指标:

> h2o.performance(fit, xval = TRUE)
H2OMultinomialMetrics: naivebayes
** Reported on cross-validation data. **
** 5-fold cross-validation on training data (Metrics computed for combined holdout predictions) **

Cross-Validation Set Metrics: 
=====================

Extract cross-validation frame with `h2o.getFrame("iris")`
MSE: (Extract with `h2o.mse`) 0.03582724
RMSE: (Extract with `h2o.rmse`) 0.1892808
Logloss: (Extract with `h2o.logloss`) 0.1321609
Mean Per-Class Error: 0.04666667
Hit Ratio Table: Extract with `h2o.hit_ratio_table(<model>,xval = TRUE)`
=======================================================================
Top-3 Hit Ratios: 
  k hit_ratio
1 1  0.953333
2 2  1.000000
3 3  1.000000

或者您可以查看特定指标,例如mean_per_class_error

> h2o.mean_per_class_error(fit, xval = TRUE)
[1] 0.04666667

如果要查看测试集的性能,可以执行以下操作:

perf <- h2o.performance(fit, test)
h2o.mean_per_class_error(perf)