标签: roc

强制roc函数(R中的软件包pROC)中输入的“ direction”自变量强制执行什么操作?

我想通过在R中使用pROC包的'roc'函数创建roc对象,并绘制roc对象。但是,我不确定“方向”论据的作用。我的控件的中值预测值小于案例的中值预测值。所以我认为正确的方向应该是“ <”。但是,如果我使用方向参数“>”进行绘制。它只是将ROC曲线在对角线上翻转为镜像。我想知道在这种情况下,数据告诉您一件事,而论点正在迫使一个不同的方向,将什么与什么进行比较,以及如何进行比较?我通读了pROC手册中有关“方向”参数的内容,其解释非常简短且不清楚。

希望听到您的一些意见!

r roc proc-r-package

4
推荐指数
1
解决办法
1340
查看次数

R获得AUC并同时绘制多条ROC曲线

我尝试了2种绘制ROC曲线并获得每个ROC曲线的AUC的方法。

方法1- 第一种方法很简单,但我不知道如何一起绘制多个ROC曲线。我只是在使用roc.curve(hacide.test$cls, pred_rose[,2]),输出将显示ROC曲线并给出AUC。

方法2 我现在可以一起绘制多条ROC曲线,但是无法同时获得AUC。这是我将多个ROC曲线绘制在一起的方式:

library(ROCR)
pd1 <- prediction(pred_rose[,2], hacide.test$cls)
pf1 <- performance(pd1, "tpr","fpr")

pd2 <- prediction(pred_both[,2], hacide.test$cls)
pf2 <- performance(pd2, "tpr","fpr")

plot(pf1, colorize = TRUE)
plot(pf2, add = TRUE, colorize = TRUE)
Run Code Online (Sandbox Code Playgroud)

这是我获得AUC的方式:

pf <- performance(pd3, "auc")
pf     # y.values is the AUC
Run Code Online (Sandbox Code Playgroud)

如您所见,当我使用第二种方法时,performance()用于获得ROC曲线和AUC的方法是不同的。此处pf1,pf2的输出没有AUC值。

方法1比较简单,但是您知道如何使用方法1一起绘制ROC曲线并仍然保留每个AUC值吗?

r roc auc

4
推荐指数
1
解决办法
8948
查看次数

ggplot2:在 ROC 图上使用scale_x_reverse

我尝试从包中plot.roc的函数重现 ROC 曲线。pRocggplot2

library(mlbench)
library(caret)

data(Sonar)

set.seed(998)
fitControl <- trainControl(method = "repeatedcv",
                           number = 10,
                           repeats = 10,
                           ## Estimate class probabilities
                           classProbs = TRUE,
                           ## Evaluate performance using 
                           ## the following function
                           summaryFunction = twoClassSummary)

gbmGrid <-  expand.grid(interaction.depth = c(1, 5, 9),
                        n.trees = (1:30)*50,
                        shrinkage = 0.1,
                        n.minobsinnode = 20)

inTraining <- createDataPartition(Sonar$Class, p = .75, list = FALSE)
training <- Sonar[ inTraining,]
testing  <- Sonar[-inTraining,]


set.seed(825)
gbmFit <- train(Class ~ ., data = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 roc

4
推荐指数
1
解决办法
1241
查看次数

预测错误 - ROCR 包(使用概率)

我使用“rfe”函数和 svm 来创建一个具有减少特征的模型。然后我对测试数据使用“预测”,输出类标签(二进制)、0 类概率、1 类概率。然后,我尝试使用 ROCR 包中的预测函数来预测概率和真实类标签,但出现以下错误,并且不确定为什么,因为两个数组的长度相等:

> pred_svm <- prediction(pred_svm_2class[,2], as.numeric(as.character(y)))
Error in prediction(pred_svm_2class[, 2], as.numeric(as.character(y))) : 
Number of predictions in each run must be equal to the number of labels for each run.
Run Code Online (Sandbox Code Playgroud)

我有下面的代码,输入在这里单击我。这是一个具有二进制分类的小数据集,因此代码运行速度很快。

library("caret")
library("ROCR")
sensor6data_2class <- read.csv("/home/sensei/clustering/svm_2labels.csv")
sensor6data_2class <- within(sensor6data_2class, Class <- as.factor(Class))

set.seed("1298356")
inTrain_svm_2class <- createDataPartition(y = sensor6data_2class$Class, p = .75, list = FALSE)
training_svm_2class <- sensor6data_2class[inTrain_svm_2class,]
testing_svm_2class <- sensor6data_2class[-inTrain_svm_2class,]
trainX <- training_svm_2class[,1:20]
y <- training_svm_2class[,21]

ctrl_svm_2class <- rfeControl(functions = rfFuncs , method …
Run Code Online (Sandbox Code Playgroud)

r roc

4
推荐指数
1
解决办法
9196
查看次数

R: Plot multiple different coloured ROC curves using ROCR

The following code was taken from @adibender answer to "Multiple ROC curves in one plot ROCR". The code is partly from ?plot.performance.

library(ROCR)
data(ROCR.simple)
preds <- cbind(p1 = ROCR.simple$predictions, 
            p2 = abs(ROCR.simple$predictions + 
            rnorm(length(ROCR.simple$predictions), 0, 0.1)))

pred.mat <- prediction(preds, labels = matrix(ROCR.simple$labels, 
            nrow = length(ROCR.simple$labels), ncol = 2) )

perf.mat <- performance(pred.mat, "tpr", "fpr")
plot(perf.mat)
Run Code Online (Sandbox Code Playgroud)

I want to illustrate several ROC curves in a single plot, like the code above, using the r package ROCR. However, i would want the …

plot r machine-learning data-mining roc

4
推荐指数
1
解决办法
6074
查看次数

将交叉验证和AUC-ROC用于sklearn中的逻辑回归模型

我正在使用该sklearn软件包来构建逻辑回归模型,然后对其进行评估。具体来说,我想使用交叉验证来执行此操作,但无法找出使用该cross_val_score函数执行此操作的正确方法。

根据文档和我看到的一些示例,我需要向函数传递模型,特征,结果和评分方法。但是,AUC不需要预测,它需要概率,因此它可以尝试不同的阈值并基于该阈值计算ROC曲线。那么什么是正确的方法呢?该函数'roc_auc'可能有一种计分方法,所以我假设它与它兼容,我只是不确定使用它的正确方法。下面的示例代码段。

from sklearn.linear_model import LogisticRegression
from sklearn.cross_validation import cross_val_score

features = ['a', 'b', 'c']
outcome = ['d']
X = df[features]
y = df[outcome]
crossval_scores = cross_val_score(LogisticRegression(), X, y, scoring='roc_auc', cv=10)
Run Code Online (Sandbox Code Playgroud)

基本上,我不明白为什么我需要传递y给我的cross_val_score功能在这里,而不是使用计算出的机率X在逻辑回归模型。它只是自己做那一部分吗?

python roc scikit-learn cross-validation logistic-regression

4
推荐指数
1
解决办法
5102
查看次数

了解 ROCR 的 performance() 函数返回的内容 - 在 R 中的分类

我很难理解 ROCR 包的 performance() 函数返回的内容。让我用一个可重现的例子来具体说明。我使用 mpg 数据集。我的代码如下:

library(ROCR)
library(ggplot2)
library(data.table)
library(caTools)
data(mpg)
setDT(mpg)
mpg[year == 1999, Year99 := 1]
mpg[year == 2008, Year99 := 0]
table(mpg$Year99)
# 0   1 
# 117 117 
split <- sample.split(mpg$Year99, SplitRatio = 0.75)
mpg_train <- mpg[split, ]
mpg_test <- mpg[!split, ]
model <- glm(Year99 ~ displ, mpg_train, family = "binomial")
summary(model)
predict_mpg_test <- predict(model, type = "response", newdata = mpg_test)
ROCR_mpg_test <- prediction(predict_mpg_test, mpg_test$Year99)
performance(ROCR_mpg_test, "acc")

#An object of class "performance"
#Slot "x.name":
#  [1] …
Run Code Online (Sandbox Code Playgroud)

performance r classification roc

4
推荐指数
1
解决办法
2322
查看次数

Keras,训练期间验证集上的auc与sklearn auc不匹配

我将测试集用作验证集。我使用了与如何计算喀拉拉邦的接收运行特征(ROC)和AUC类似的方法

问题是我在训练期间的val_auc约为0.85,但是当我使用

fpr, tpr, _ = roc_curve(test_label, test_prediction)
roc_auc = auc(fpr, tpr)
Run Code Online (Sandbox Code Playgroud)

我得到0.60的auc。我知道他们使用不同的公式,并且流式auc可能与sklearn计算的公式不同。但是,差异非常大,我无法弄清是什么原因造成了这种差异。

# define roc_callback, inspired by https://github.com/keras-team/keras/issues/6050#issuecomment-329996505
def auc_roc(y_true, y_pred):
    # any tensorflow metric
    value, update_op = tf.contrib.metrics.streaming_auc(y_pred, y_true)

    # find all variables created for this metric
    metric_vars = [i for i in tf.local_variables() if 'auc_roc' in i.name.split('/')[1]]

    # Add metric variables to GLOBAL_VARIABLES collection.
    # They will be initialized for new session.
    for v in metric_vars:
        tf.add_to_collection(tf.GraphKeys.GLOBAL_VARIABLES, v)

    # force to update metric values …
Run Code Online (Sandbox Code Playgroud)

roc scikit-learn auc keras tensorflow

4
推荐指数
1
解决办法
1232
查看次数

ROC 函数错误“预测器必须是数字或有序的。”

我无法使 ROC 函数工作,出现错误“预测器必须是数字或有序”。

我浏览了其他帖子,但没有解决我的问题。任何帮助都受到高度赞赏。

"Get data"
flying=dget("https://www.math.ntnu.no/emner/TMA4268/2019v/data/flying.dd")
ctrain=flying$ctrain
ctest=flying$ctest


library(MASS)
fly_qda=qda(diabetes~., data=ctrain)


#Test error is given below:
predict_qda=predict(fly_qda, newdata=ctest, probability=TRUE)
table_qda<-table(ctest$diabetes, predict_qda$class)
error_qda<-1-sum(diag(table_qda))/sum(table_qda)
error_qda

"ROC curve and AUC"
predict_qdatrain<-predict(fly_qda, newdata=ctrain)
roc_qda=roc(response=ctrain$diabetes, predictor= predict_qdatrain$class, plot=TRUE)
plot(roc_qda, col="red", lwd=3, main="ROC curve QDA")
auc_qda<-auc(roc_qda)
Run Code Online (Sandbox Code Playgroud)

我想要绘制的 ROC 曲线和 AUC

r roc proc-r-package

4
推荐指数
1
解决办法
8693
查看次数

如何使用 pRoc 包进行 ROC 分析后获得 p 值?

对一组数据进行ROC分析后,如何计算p-value?通过同样的统计,我看到SPSS中可以输出p值。示例代码如下:

library(pROC)
data(aSAH)
head(aSAH)
#    gos6 outcome gender age wfns s100b  ndka
# 29    5    Good Female  42    1  0.13  3.01
# 30    5    Good Female  37    1  0.14  8.54
# 31    5    Good Female  42    1  0.10  8.09
# 32    5    Good Female  27    1  0.04 10.42
# 33    1    Poor Female  42    3  0.13 17.40
# 34    1    Poor   Male  48    2  0.10 12.75

(rr <- roc(aSAH$outcome, aSAH$s100b, plot=T))
# Setting levels: control = Good, case = Poor …
Run Code Online (Sandbox Code Playgroud)

r spss roc proc-r-package

4
推荐指数
1
解决办法
4349
查看次数