logistic-regression - 泰坦尼克号数据集。逻辑回归模型。混淆矩阵给出 0 作为输出
问题描述
我正在使用以下代码在 Titanic 数据集上运行逻辑回归模型:
#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
无法理解此错误消息以及出了什么问题。该模型在火车数据上运行良好。我假设它与我应用于幸存变量的阈值有关(这是一个因子变量 - 1,0)。
解决方案
推荐阅读
- css - 如何在键盘可访问性焦点上关闭汉堡菜单
- r - prcomp R 基函数中的主动变量和补充变量
- python - 给定像素 (x,y) 位置返回 (row, column) 元组
- php - 如何使用 PHP 更新现有的数组数组?
- javascript - Javascript 生成器不会产生新的结果
- c# - 天蓝色函数时间触发器和天蓝色sql数据库与c#之间的连接:错误。如何修复它
- scala - 如何将查询写入 es.query
- html - 如何通过 pathVariable 在 url 中使用我的 HTML 表单的字段?
- java - Android自定义视图onDraw方法在第二次启动活动无效后未调用
- swift - swift MaterialComponents.MDCTabBarView mdc_customView 无法正常工作