-2
我正在繪製使用由插入符R包創建的測試/火車集的模型的ROC曲線。我要麼沒有把正確的數據輸入到繪圖中,要麼錯過了創建我的測試/訓練集的信息。任何見解?火車/測試設置在插入符R包中的ROC曲線R包
*編輯與正確答案
library(caret)
library(mlbench)
set.seed(506)
data(whas)
inTrain <- createDataPartition(y = whas$bin.frail,
p = .75, list = FALSE)
str(inTrain)
training <- whas[ inTrain,]
testing <- whas[-inTrain,]
nrow(training)
nrow(testing)
tc <- trainControl("cv", 10, savePredictions=T) #"cv" = cross-validation, 10-fold
mod1 <- train(bin.frail ~ ,
data = training ,
method = "glm" ,
family = binomial ,
trControl = tc)
library(pROC)
mod1pred<- predict(mod1, newdata=testingresponse="prob")
plot(roc(testing$bin.frail, mod1pred[[2]]), print.auc=TRUE, col="red",
xlim=c(0,1))
在你的問題中包括一個[最小可重現的例子](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)將增加你獲得答案的機會。 – jsb
這兩個班級不是'caret'返回概率嗎?如果是這樣,請確保只傳遞「正」類概率。 –
什麼軟件包包含'whas'數據集?按照現狀,我們無法重現您的問題。 – josliber