我的预测值都是负数。我本来期待0或1。谁能看到我哪里错了?
fold = 10
end = nrow(birthwt)
fold_2 = floor(end/fold)
df_i = birthwt[sample(nrow(birthwt)),] # random sort the dataframe birthwt
tester = df_i[1:fold_2,] # remove first tenth of rows - USE PREDICT ON THIS DATA
trainer = df_i[-c(1:fold_2),] # all other than the first tenth of rows - USE GLM ON THIS DATA
mod = glm(low~lwt,family=binomial,data=trainer)
ypred = predict(mod,data=tester) # predicted values
答案 0 :(得分:2)
predict.glm
的默认值是在转换之前为您提供链接的值(在线性预测变量的比例上)。如果要预测响应,请使用
ypred <- predict(mod, data=tester, type="response")
如果阅读?predict.glm
帮助文件可能会有所帮助。