ROCR软件包的预测功能给出错误:“预测”包含不适用

时间:2020-06-21 11:41:40

标签: r analytics na roc edx

我一直关注Edx course The Analytics Edge,目前在逻辑回归部分:弗雷明汉心脏研究部分。

此处,他们使用ROCR包的预测功能来预测阈值设置为0.5的数据准确性。我已经从edx课程门户网站下载了.csv文件,并编写了完全相同的代码,但是出现了“预测”包含不适用的错误。

这是代码:

framingham <- read.csv("framingham.csv")

library(caTools)

# framingham <- na.omit(framingham) # If I use this line then the code works fine but people must be working all the time with data with missing values. So, it should work for all the cases too. 

set.seed(1000)

split <- sample.split(framingham$TenYearCHD, SplitRatio = 0.65)

train <- subset(framingham, split == TRUE)

test <- subset(framingham, split == FALSE)

framinghamLog <- glm(TenYearCHD ~ ., data = train, family = binomial)

summary(framinghamLog)

predictTest <- predict(framinghamLog, type = "response", newdata = test)

table(test$TenYearCHD, predictTest > 0.5)

library(ROCR)

ROCRpred <- prediction(predictTest, test$TenYearCHD)

这是错误:

Error: 'predictions' contains NA.

0 个答案:

没有答案