因子字段状态的预报()上的对象错误

问题描述 投票:0回答:1

问题上下文:用于预测的模型响应变量“状态”。帮助上下文:UseMethod(“ predict”)中的错误。我的想法是领域“状态”因素是问题。在预测问题时需要帮助。

R代码:

model.predict <- predict(model.fit, newdata = loans_train_data, type="response")

结构数据:

str(loans_train_data)
'data.frame: 
$amount:num...
$...
$status: factor w/2 levels "Good", "Bad": 2, 1, 2, 1, 1, 1, 1 ...

UseMethod(“ predict”)中的错误

Error in UseMethod("predict") : 
no applicable method for 'predict' applied to an object of class "c('double', 'numeric')"

有效的方法:

model.lm <- glm2(formula, data=loans_train_data, family="binomial")
model.fit <- fitted(model.lm)

预测失败,在UseMethod(“ predict”)中出错。

model.predict <- predict(model.fit, newdata=loans_train_data, type="response")
r predict
1个回答
1
投票

在model.lm上使用预测。根据fittedhttps://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/fitted的文档,它提取值的向量,而不是模型本身。

© www.soinside.com 2019 - 2024. All rights reserved.