Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

Train function from R caret package error: "Something is wrong; all the Accuracy metric values are missing"

I want to run a logreg regression. I obtain the following error after running my code on R:

Something is wrong; all the Accuracy metric values are missing:

    Accuracy       Kappa    
 Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA  
 NA's   :9     NA's   :9    
Error in train.default(x, y, weights = w, ...) : Stopping
In addition: There were 19 warnings (use warnings() to see them)

Here is my code:

## Data
donner <- read.delim("http://web.as.uky.edu/statistics/users/pbreheny/760/data/donner.txt")
set.seed(1234)
library(caret)
donner$Age <- as.numeric(donner$Age)
donner$Status <- as.factor(donner$Status)  
donner$Sex <- as.numeric(donner$Sex) 
splitIndex <- createDataPartition(donner$Status, p = .80, list = FALSE, times = 1)
trainDF <- donner[splitIndex,]
testDF <- donner[-splitIndex,]
ctrl <- trainControl(method = "cv", number = 2)
logregmodel <- train(Status ~ ., data = donner, method = "logreg", trControl = ctrl)

EDIT 1:

I changed the status to binary (0 and 1) and I still have some errors. Here is the new code:

## Data
donner <- read.delim("http://web.as.uky.edu/statistics/users/pbreheny/760/data/donner.txt")
set.seed(1234)
library(caret)
donner$Age <- as.numeric(donner$Age)
donner$Status <- as.integer(donner$Status)-1  
donner$Sex <- as.numeric(donner$Sex)-1 
splitIndex <- createDataPartition(donner$Status, p = .80, list = FALSE, times = 1)
trainDF <- donner[splitIndex,]
testDF <- donner[-splitIndex,]
ctrl <- trainControl(method = "cv", number = 2)
donner$Status <- as.factor(donner$Status)
logregmodel <- train(Status ~ ., data = donner, method = "logreg", trControl = ctrl)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just needed to fix your data. Logic Regression -- which is what I'm assuming you want, since you called the logic regression (logreg) method and this entire question is aside from the point if you're wanting something else like logit model, which would never give you the error in the first place -- is for binary variables only and it doesn't understand that 1's and 2's can represent binary data. It wants literal 0's and 1's.

donner <- read.delim("http://web.as.uky.edu/statistics/users/pbreheny/760/data/donner.txt")
set.seed(1234)
library(caret)
donner$Age <- as.numeric(donner$Age)
donner$Status <- as.factor(donner$Status)  
donner$Sex <- as.numeric(donner$Sex) 
splitIndex <- createDataPartition(donner$Status, p = .80, list = FALSE, times = 1)
trainDF <- donner[splitIndex,]
testDF <- donner[-splitIndex,]
ctrl <- trainControl(method = "cv", number = 3)
donner$Status <- as.character(donner$Status)
donner$Status[!donner$Status == "Survived"] <- 0
donner$Status[donner$Status == "Survived"] <- 1
donner$Age_gr_mean <- 0
donner$Age_gr_mean[donner$Age_gr_mean > mean(donner$Age)] <- 1
donner$Age <- NULL
donner$Status <- as.numeric(donner$Status)
donner$Sex[donner$Sex == 2] <- 0
logregmodel <- train(Status ~ ., data = donner, method = "logreg", trControl = ctrl)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...