R 从nnet模型计算AUC

R 从nnet模型计算AUC,r,neural-network,R,Neural Network,作为一点背景知识,我正在使用nnet包构建一个简单的神经网络 我的数据集具有许多因子和连续变量特征。为了处理连续变量,我应用了scale和center,这两个变量用其平均值减去,用其SD除以 我正试图根据神经网络模型的结果绘制ROC和AUC图 下面是用于构建我的基本神经网络模型的代码: model1 <- nnet(Cohort ~ .-Cohort, data = train.sample, size = 1) 但我有一个错误: match

作为一点背景知识,我正在使用
nnet
包构建一个简单的神经网络

我的数据集具有许多因子和连续变量特征。为了处理连续变量,我应用了
scale
center
,这两个变量用其平均值减去,用其SD除以

我正试图根据神经网络模型的结果绘制ROC和AUC图

下面是用于构建我的基本神经网络模型的代码:

model1 <- nnet(Cohort ~ .-Cohort, 
           data = train.sample,
           size = 1)
但我有一个错误:

match.arg(类型)中出错:'arg'应为“原始”、“类”之一


如何从输出中获取类概率

假设您的测试/验证数据集位于
train.test
中,并且train.labels包含真正的类标签:

train.predictions <- predict(model1, train.test, type="raw")

## This might not be necessary:
detach(package:nnet,unload = T)

library(ROCR)

## train.labels:= A vector, matrix, list, or data frame containing the true  
## class labels. Must have the same dimensions as 'predictions'.

## computing a simple ROC curve (x-axis: fpr, y-axis: tpr)
pred = prediction(train.predictions, train.labels)
perf = performance(pred, "tpr", "fpr")
plot(perf, lwd=2, col="blue", main="ROC - Title")
abline(a=0, b=1)

train.predictions谢谢你的帮助。在做了一些研究之后,我认为train函数的
classProbs
参数也将返回类概率以及实际预测
train.predictions <- predict(model1, train.sample, type="prob")
train.predictions <- predict(model1, train.test, type="raw")

## This might not be necessary:
detach(package:nnet,unload = T)

library(ROCR)

## train.labels:= A vector, matrix, list, or data frame containing the true  
## class labels. Must have the same dimensions as 'predictions'.

## computing a simple ROC curve (x-axis: fpr, y-axis: tpr)
pred = prediction(train.predictions, train.labels)
perf = performance(pred, "tpr", "fpr")
plot(perf, lwd=2, col="blue", main="ROC - Title")
abline(a=0, b=1)