Titani c Набор данных. Logisti c Модель регрессии. Путаница Матрица дает 0 в качестве вывода - PullRequest
1 голос
/ 29 января 2020

Я использую модель регрессии logisti c на наборе данных Titani c со следующим кодом:

#Modeling

#Split into train and test and fit the logistic regression model


titanic_train <- titanic_complete[1:891,]
titanic_test <- titanic_complete[892:1309,]

##############Logistic Regression ###############################

glm_model = glm(Survived~.,data= titanic_train, family = 'binomial')
summary(glm_model)


## Using anova() to analyze the table of devaiance
anova(glm_model, test="Chisq")


final_model = glm(Survived~Sex + Pclass + Age + SibSp + Cabin_f, data = titanic_train, family = 'binomial')
summary(final_model)

varImp(glm_model)

glm.pred <-predict(final_model, titanic_test, type = 'response')
glm.pred <- ifelse(glm.pred > 0.5, "yes", "no")

glm.pred

confusionMatrix(glm.pred, titanic_test$Survived)

В результате у меня появляется это сообщение об ошибке:

> confusionMatrix(glm.pred, titanic_test$Survived)
[1] no  yes
<0 rows> (or 0-length row.names)
In Ops.factor(predictedScores, threshold) :
  ‘<’ not meaningful for factors

Не могу понять это сообщение об ошибке и что не так. Модель отлично работает на данных поезда. Я предполагаю, что это связано с порогом, который я применяю к переменной Survived (которая является факторной переменной - 1,0).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...