【发布时间】:2026-02-21 00:40:01
【问题描述】:
我目前正在尝试建立一个多类预测模型来预测 26 个英文字母中的字母。我目前使用 ANN、SVM、Ensemble 和 nB 构建了一些模型。但我坚持评估这些模型的准确性。尽管混淆矩阵向我展示了按字母顺序进行的真假预测,但我只能获得每个模型的整体准确性。有没有一种方法可以评估模型的准确性,类似于二项式分类的 ROC 和 AUC 值。 注意:我目前正在使用 H2o 包运行模型,因为它可以节省更多时间。
【问题讨论】:
我目前正在尝试建立一个多类预测模型来预测 26 个英文字母中的字母。我目前使用 ANN、SVM、Ensemble 和 nB 构建了一些模型。但我坚持评估这些模型的准确性。尽管混淆矩阵向我展示了按字母顺序进行的真假预测,但我只能获得每个模型的整体准确性。有没有一种方法可以评估模型的准确性,类似于二项式分类的 ROC 和 AUC 值。 注意:我目前正在使用 H2o 包运行模型,因为它可以节省更多时间。
【问题讨论】:
在 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)
【讨论】:
mean_per_class_error 来选择最佳模型。