在使用Logistic回归的过程中使用预测时遇到问题

时间:2019-08-24 16:37:13

标签: r logistic-regression

我正在尝试使用大学橄榄球统计数据线建立预测值,以预测获利和损失。我在R中使用逻辑回归,但在预测时遇到问题:

Error: variable 'Spread' was fitted with type "factor" but type "numeric" was supplied
In addition: Warning message:
In model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
  variable 'Spread' is not a factor

尝试建立表时,我也遇到错误,提示未找到对象W.L

我已经尝试将训练数据和预测数据中的变量分布从一个因子更改为一个数字。都没用

library("aod") 
library("ggplot2")
setwd("C:/Users/ryant/Desktop/Working")
MyData <- read.csv(file="milk.csv", header=TRUE, sep=",")
head(MyData)
summary(MyData)
#as.numeric(as.character(Spread))
mylogit <- glm(W.L ~ Ranking + Recruiting.Rating + FPI + Spread, data = MyData, family = "binomial")
summary(mylogit)
glm.probs <- predict(mylogit,type = "response")
glm.probs[1:5]
glm.pred <- ifelse(glm.probs > 0.90,"1","0")
#attach(MyData)
table(glm.pred,W.L)
mean(glm.pred == W.L)
Bread <- read.csv(file="bread.csv", header=TRUE, sep=",")
#as.numeric(as.character(Spread))
predict(mylogit,newdata = Bread, type = "response")

我希望当我将新季节的数据点(包括glm编码中列出的因素)反馈给W.L时,我的代码可以对W.L做出预测。相反,我收到列出的错误消息

0 个答案:

没有答案