【问题标题】:How to make the confusion matrix in this case? [closed]在这种情况下如何制作混淆矩阵? [关闭]
【发布时间】:2017-09-27 06:31:44
【问题描述】:
library(h2o)
h2o.init(nthreads=-1)
test <- h2o.importFile(path = "C:/Users/AkshayJ/Documents/newapril/data/testdata.csv")
train <- h2o.importFile(path = "C:/Users/AkshayJ/Documents/newapril/data/traindata.csv")
y <- "Label"
train[,y] <- as.factor(train[,y])
test[,y] <- as.factor(test[,y])
train[,"Allele1Top"] <- as.factor(train[,"Allele1Top"])
test[,"Allele1Top"] <- as.factor(test[,"Allele1Top"])
train[,"Allele2Top"] <- as.factor(train[,"Allele2Top"])
test[,"Allele2Top"] <- as.factor(test[,"Allele2Top"])
train[,"Allele1Forward"] <- as.factor(train[,"Allele1Forward"])
test[,"Allele1Forward"] <- as.factor(test[,"Allele1Forward"])
train[,"Allele2Forward"] <- as.factor(train[,"Allele2Forward"])
test[,"Allele2Forward"] <- as.factor(test[,"Allele2Forward"])
train[,"Allele1AB"] <- as.factor(train[,"Allele1AB"])
test[,"Allele1AB"] <- as.factor(test[,"Allele1AB"])
train[,"Allele2AB"] <- as.factor(train[,"Allele2AB"])
test[,"Allele2AB"] <- as.factor(test[,"Allele2AB"])
train[,"Chr"] <- as.factor(train[,"Chr"])
test[,"Chr"] <- as.factor(test[,"Chr"])
train[,"SNP"] <- as.factor(train[,"SNP"])
test[,"SNP"] <- as.factor(test[,"SNP"])
x <- setdiff(names(train),y)
model <- h2o.deeplearning(
x = x,
y = y,
training_frame = train,
validation_frame = test,
distribution = "multinomial",
activation = "RectifierWithDropout",
hidden = c(32,32,32),
input_dropout_ratio = 0.2,
sparse = TRUE,
l1 = 1e-5,
epochs = 10)
predic <- h2o.predict(model, newdata = test)
table(pred=predic, true = test[,21])

一切都很好,但最后一行 表(pred=predic,true = test[,21]) 给出错误 unique.default(x, nmax = nmax) 中的错误: 向量分配中的类型/长度(环境/0)无效

【问题讨论】:

  • 重新打开原因:虽然代码示例不是最小的(也不是可重现的,因为没有包含数据),但足以理解问题并能够回答它。
  • Akshay,对于分类问题(像这样),使用 iris 数据集通常是好的(h2o 检测 iris 数据中的列类型也没有问题,所以不需要弄乱你的最小代码as.factor() 行)。
  • 好的...记住这一点

标签: r machine-learning deep-learning h2o


【解决方案1】:

使用函数h2o.confusionMatrix() 得到混淆矩阵。简单的方法是给它模型,以及你想要分析的数据:

h2o.confusionMatrix(model, test)

如果您查看?h2o.confusionMatrix,您会发现它也可以接受H2OModelMetrics 对象。您可以致电h2o.performance() 获得其中之一:

p = h2o.performance(model, test)
h2o.confusionMatrix(p)

我推荐第二种方式,因为p 对象包含有关您的模型有多好的其他有用信息。

注意:无论哪种方式,您都没有使用您的预测。基本上:

  • h2o.performance如果你想分析模型的质量。
  • h2o.predict 如果你想得到实际的预测。

【讨论】:

  • 我尝试了两种方法,但我得到了相同的输出:一个混淆矩阵,具有相同的值、错误和阈值。为什么你更喜欢第二种方式(h2o.confusionMatrix(p))
  • @DavidLeal 因为如果我打印p,它不仅会告诉我混淆矩阵,还会告诉我 MSE、RMSE、Logloss、命中率等。它也是您为各个函数提供的参数,例如h2o.mse(p)
猜你喜欢
  • 1970-01-01
  • 2020-12-27
  • 2016-03-27
  • 2016-11-21
  • 1970-01-01
  • 1970-01-01
  • 2018-11-22
  • 2018-09-30
  • 1970-01-01
相关资源
最近更新 更多