4
$\begingroup$

After trying to do som e cross validation i got some models that fitted the data fairly good but predicted them horribly (eg. fitted = [10001.543,10034.324,104023.23..], true value = [10001,543,10034,104023] and predicted = [10.22,9.44,11.323...])

For you who is a bit more experienced than i am, How can it be possible that when predicting the same data a model i based on can be so differ so much? what is the difference when the model predics something vs when it fits?

I am using poisson regression on data for you who wonder

Data1 <- data.frame(var1,var2,var3,var4,var5,var6)
data_file <- Data1[50:200,]
data_file2 <- Data1[1:50,]

model1 <- glm(var1~var2+var3+offset(log(var4)),data=data_file,family="poisson"

So what i was about to do was a K-fold cross validation so i split the data up in two variables.

pred <- predict(model1,data_file2)
pred
data_file2[,1]
model1$fitted.values

the last 3 lines gave the following results:

[10.22,9.44,11.323...]

[10001,543,10034,104023]

[10001.543,10034.324,104023.23..],

$\endgroup$
5
  • $\begingroup$ Could you post some code and results? It would help figure out what could be going on in your analyses. $\endgroup$
    – Mark White
    Commented May 14, 2017 at 20:15
  • $\begingroup$ i was asking in general on how this can occur, thought it was a rather normal thing that occurs often. But sure no problem @markWhite $\endgroup$
    – Janono
    Commented May 14, 2017 at 20:17
  • $\begingroup$ What is your variable var4? Could you add data_file2[,4] in your output? $\endgroup$
    – user158565
    Commented May 15, 2017 at 1:27
  • $\begingroup$ it's about 290 rows long so maybe not output all of it hehe var4 is population data based on swedish communities where each row is the number of inhabitants in a certain communities. Var4 = [1823210 ,294196 , 256033 , 411345 , 327829 ,176639] @a_statistician $\endgroup$
    – Janono
    Commented May 15, 2017 at 12:24
  • $\begingroup$ Maybe "pred" just give you $X\beta$, and you need $\exp(X\beta)$. You can check the software manual to see what "pred" really mean. In addition, you can calculate $X\beta$ by hand (calculator) for first 3 cases to see if you can get 10.22, 9.44, 11.323,.... $\endgroup$
    – user158565
    Commented May 15, 2017 at 13:28

1 Answer 1

5
$\begingroup$

Regression methods aim to model your data in a relatively simple way. This is achieved by assuming the data is distributed by some parameterized known distribution, and then fitting these parameters. The model doesn't have to generate the exact same values for each data sample (which causes bad generalization. e.g. predicting bad values for new data).

Consider the problem of fitting some polynomial of degree $d$ to your data. As you increase $d$, the polynomial is more likely to fit your training data exactly . But will it generalize well? consider this example (taken from here): enter image description here The middle polynomials ($d=2$) seems most promising, but the third option predicts a closer values for each training example. Still, we would consider the second polynomial as "better" in this case.

In your case, it seems like the model is underfitting your data. This is illustrated in the left polynomial above ($d=1$). You should verify that you are training it correctly, use different model parameters or try a different model.

$\endgroup$
4
  • $\begingroup$ so the issue can be explained by claiming that the model is either worthless or simply overfitting? $\endgroup$
    – Janono
    Commented May 14, 2017 at 20:36
  • $\begingroup$ @Janono I believe it is underfitting. I've added more details about that at the end of my post. $\endgroup$
    – mbrg
    Commented May 14, 2017 at 20:41
  • $\begingroup$ sorry, i meant underfitting :P @mibarg $\endgroup$
    – Janono
    Commented May 14, 2017 at 20:44
  • $\begingroup$ @Janono Yes, I believe that is the case. $\endgroup$
    – mbrg
    Commented May 14, 2017 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.