R - 负值预测中的k-交叉验证

时间:2014-11-11 22:44:27

标签: r

我的预测值都是负数。我本来期待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

1 个答案:

答案 0 :(得分:2)

predict.glm的默认值是在转换之前为您提供链接的值(在线性预测变量的比例上)。如果要预测响应,请使用

ypred <- predict(mod, data=tester, type="response") 

如果阅读?predict.glm帮助文件可能会有所帮助。