Monday, 15 June 2015

k-Fold Cross Validation in R - Negative Value Predictions -



k-Fold Cross Validation in R - Negative Value Predictions -

my predicted values negative. have expected 0's or 1's. can see going wrong?

fold = 10 end = nrow(birthwt) fold_2 = floor(end/fold) df_i = birthwt[sample(nrow(birthwt)),] # random sort dataframe birthwt tester = df_i[1:fold_2,] # remove first 10th of rows - utilize predict on info trainer = df_i[-c(1:fold_2),] # other first 10th of rows - utilize glm on info mod = glm(low~lwt,family=binomial,data=trainer) ypred = predict(mod,data=tester) # predicted values

the default predict.glm give value of link (on scale of linear predictors) before transformation. if want predict response, utilize

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

if may helpful read ?predict.glm help file.

r

No comments:

Post a Comment