从 glmnet 获得我的预测后,我尝试使用“ROCR”包中的“预测”函数来获取 tpr、fpr 等,但出现此错误:
pred <- prediction(pred_glmnet_s5_3class, y)
Error in prediction(pred_glmnet_s5_3class, y) :
Format of predictions is invalid.
我已经输出了 glmnet 预测和标签,它们看起来格式相似,因此我不明白这里什么是无效的。
代码如下,输入可以在这里找到input。这是一个小数据集,运行时间应该不会太长。
library("ROCR")
library("caret")
sensor6data_s5_3class <- read.csv("/home/sensei/clustering /sensor6data_f21_s5_with3Labels.csv")
sensor6data_s5_3class <- within(sensor6data_s5_3class, Class <- as.factor(Class))
sensor6data_s5_3class$Class2 <- relevel(sensor6data_s5_3class$Class,ref="1")
set.seed("4321")
inTrain_s5_3class <- createDataPartition(y = sensor6data_s5_3class$Class, p = .75, list = FALSE)
training_s5_3class <- sensor6data_s5_3class[inTrain_s5_3class,]
testing_s5_3class <- sensor6data_s5_3class[-inTrain_s5_3class,]
y <- testing_s5_3class[,22]
ctrl_s5_3class <- trainControl(method = "repeatedcv", number = 10, repeats = 10 , savePredictions = TRUE)
model_train_glmnet_s5_3class <- train(Class2 ~ ZCR + Energy + SpectralC + SpectralS + SpectralE + SpectralF + SpectralR + MFCC1 + MFCC2 + MFCC3 + MFCC4 + MFCC5 + MFCC6 + MFCC7 + MFCC8 + MFCC9 + MFCC10 + MFCC11 + MFCC12 + MFCC13, data = training_s5_3class, method="glmnet", trControl = ctrl_s5_3class)
pred_glmnet_s5_3class = predict(model_train_glmnet_s5_3class, newdata=testing_s5_3class, s = "model_train_glmnet_s5_3class$finalModel$lambdaOpt")
pred <- prediction(pred_glmnet_s5_3class, y)
感谢你的帮助!