如何评估 R 中的多项分类模型?
How do I evaluate a multinomial classification model in R?
我目前正在尝试建立一个多 class 预测模型来预测 26 个英文字母表中的字母。我目前已经使用 ANN、SVM、Ensemble 和 nB 构建了一些模型。但我坚持评估这些模型的准确性。尽管混淆矩阵向我显示了字母表的正确和错误预测,但我只能获得每个模型的整体准确性。有没有一种方法可以评估模型的准确性,类似于二项式分类的 ROC 和 AUC 值。
注意:我目前 运行 使用 H2o 包的模型,因为它可以节省我更多时间。
在 H2O 中训练模型后,如果您只需执行以下操作:print(fit)
它将向您显示该模型类型的所有可用指标。对于多类,我建议 h2o.mean_per_class_error()
.
iris 数据集上的 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)
我目前正在尝试建立一个多 class 预测模型来预测 26 个英文字母表中的字母。我目前已经使用 ANN、SVM、Ensemble 和 nB 构建了一些模型。但我坚持评估这些模型的准确性。尽管混淆矩阵向我显示了字母表的正确和错误预测,但我只能获得每个模型的整体准确性。有没有一种方法可以评估模型的准确性,类似于二项式分类的 ROC 和 AUC 值。 注意:我目前 运行 使用 H2o 包的模型,因为它可以节省我更多时间。
在 H2O 中训练模型后,如果您只需执行以下操作:print(fit)
它将向您显示该模型类型的所有可用指标。对于多类,我建议 h2o.mean_per_class_error()
.
iris 数据集上的 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)