Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试在R中创建ROC曲线时,预测函数出错_R_Prediction_Curve_Roc - Fatal编程技术网

尝试在R中创建ROC曲线时,预测函数出错

尝试在R中创建ROC曲线时,预测函数出错,r,prediction,curve,roc,R,Prediction,Curve,Roc,在对UCI存储库中提供的印度肝脏患者数据集进行分类后,尝试实现ROC曲线。得到一个错误。下面是R中的代码,后面是错误,后面是数据集头部的dput 代码 数据集 structure(list(age = c(55L, 48L, 14L, 17L, 40L, 37L), gender = c(0L, 0L, 0L, 0L, 1L, 0L), TB = c(0.9, 2.4, 0.9, 0.9, 0.9, 0.7), DB = c(0.2, 1.1, 0.3, 0.2, 0.3, 0.2), Al

在对UCI存储库中提供的印度肝脏患者数据集进行分类后,尝试实现ROC曲线。得到一个错误。下面是R中的代码,后面是错误,后面是数据集头部的dput

代码

数据集

structure(list(age = c(55L, 48L, 14L, 17L, 40L, 37L), gender = c(0L, 
0L, 0L, 0L, 1L, 0L), TB = c(0.9, 2.4, 0.9, 0.9, 0.9, 0.7), DB = c(0.2, 
1.1, 0.3, 0.2, 0.3, 0.2), Alkphos = c(116L, 554L, 310L, 224L, 
293L, 235L), SGPT = c(36L, 141L, 21L, 36L, 232L, 96L), sgot = c(16L, 
73L, 16L, 45L, 245L, 54L), TP = c(6.2, 7.5, 8.1, 6.9, 6.8, 9.5
), ALB = c(3.2, 3.6, 4.2, 4.2, 3.1, 4.9), AG = c(1, 0.9, 1, 1.55, 
0.8, 1), Class = structure(c(2L, 1L, 2L, 1L, 1L, 1L), .Label = c("One", 
"Two"), class = "factor")), .Names = c("age", "gender", "TB", 
"DB", "Alkphos", "SGPT", "sgot", "TP", "ALB", "AG", "Class"), row.names =    c(216L, 
405L, 316L, 103L, 20L, 268L), class = "data.frame")

我可以得到ROC曲线,但现在我对它的解释感到困惑。需要进一步的帮助。

问题是当
prediction()
查找数值向量时,
prob
是一个因子

SVM自然输出类预测,但您可以覆盖它并使用

#svm here, note the probability=TRUE
svmmodel<-svm(Class~.,train,
              kernel="sigmoid", probability = TRUE)

## In the ?predict.svm you can see probability = TRUE is needed to output probability
## type="repsonse" and type = "prob" would do nothing. 
pred.output <-predict(svmmodel,test,probability = TRUE)

## It outputs the probabilities as an attribute, so you need to go in an grab them
prob <- attr(pred.output, "probabilities")[,2]


pred <- prediction(prob, test$Class) #Now this works
#这里,请注意概率=TRUE

svmmodel问题在于当
prediction()
查找数值向量时,
prob
是因子

SVM自然输出类预测,但您可以覆盖它并使用

#svm here, note the probability=TRUE
svmmodel<-svm(Class~.,train,
              kernel="sigmoid", probability = TRUE)

## In the ?predict.svm you can see probability = TRUE is needed to output probability
## type="repsonse" and type = "prob" would do nothing. 
pred.output <-predict(svmmodel,test,probability = TRUE)

## It outputs the probabilities as an attribute, so you need to go in an grab them
prob <- attr(pred.output, "probabilities")[,2]


pred <- prediction(prob, test$Class) #Now this works
#这里,请注意概率=TRUE
svmmodel
#svm here, note the probability=TRUE
svmmodel<-svm(Class~.,train,
              kernel="sigmoid", probability = TRUE)

## In the ?predict.svm you can see probability = TRUE is needed to output probability
## type="repsonse" and type = "prob" would do nothing. 
pred.output <-predict(svmmodel,test,probability = TRUE)

## It outputs the probabilities as an attribute, so you need to go in an grab them
prob <- attr(pred.output, "probabilities")[,2]


pred <- prediction(prob, test$Class) #Now this works