I am using the mgcv package in R. I trained a GAM, for a binary classification task, so I used binomial as a family. But when I run the predict method on the Test Set, I don't get 0 or 1 output, but numeric values. Why does mgcv provide these outputs? How do I get binary outputs?
Asked
Active
Viewed 120 times
1 Answers
1
The predictions are on the scale of the link function, in the form of log odds. Even if you changes the predictions to be on the response scale, the response scale is in terms of probability, bounded between 0 and 1. This is what the actual model you fitted, the expected probability of the event. This is unlike other class prediction tools like trees, which typically give back a predicted class (although in the case of trees, this class is often majority vote, so it includes some form of decision rule to output the 0 and 1 class).
You will need to come up with a decision rule to convert the probability of the event/feature into a binary prediction of either 0 or 1.

Gavin Simpson
- 37,567
- 5
- 110
- 153
-
Perfect, thank you very much I understand !! So, for example, it will be enough for me to associate class 1 if the output probability is greater than 0.5, otherwise 0. – Francesco Ladogana Sep 08 '20 at 18:41
-
1@FrancescoLadogana Watch out for treating $0.5$ as the magic threshold. There are a number of posts on here about proper scoring rules. The accepted answer here has a good discussion, and the links in that answer (and the links in the linked pages, etc) are good reads. – Dave Sep 08 '20 at 19:44
-
@Dave +1 Was just about to respond similarly – Gavin Simpson Sep 08 '20 at 19:54
-
1It would help if I included the link... https://stats.stackexchange.com/questions/464636/proper-scoring-rule-when-there-is-a-decision-to-make-e-g-spam-vs-ham-email – Dave Sep 08 '20 at 19:56
-
Perfect I get it, thank you very much for this tip !! – Francesco Ladogana Sep 08 '20 at 20:59