# Overfitting a logistic regression model

Is it possible to overfit a logistic regression model? I saw a video saying that if my area under the ROC curve is higher than 95%, then its very likely to be over fitted, but is it possible to overfit a logistic regression model?

• Can you say which video, or at least give a little more context? Oct 12 '13 at 5:43
• Sure @Glen_b, the video was this: link The comment was at 40min. It was saying that thing: when ROC have the AUC between 0,5 and 0,6 it was Poor. If between 0,6 and 0,7 it´s below average. If between 0,7 and 0,75 it´s a average/Good. It betwwen 0,75 and 0,8 it´s good. If between 0,8 and 0,9 its Excelent. If higher than 0,9 it´s suspicious and if higher then 0,95 it´s overfitted. I´ve found that explanation very easy to understand, but it´s right? Because I´m searching for something to backup that thought but i´m not finding. Oct 12 '13 at 10:35
• And Glen_B, the explanation that @AdamO gave seems that the explanation that I saw on video wasn´t exactly right, but maybe I´ve misanderstood Adam´s explanation. These Statiscs stuff is very complex, but It´s a real pleasure to dig deep into it. :) Oct 12 '13 at 10:38
• I think AdamO's explanation is good (I upvoted it), but questions are supposed to be permanent resources; a later reader (e.g. someone with a similar question) may want the context of knowing what was said. I think your description in the comment gives enough context for most people and the link will do for the rest. So thank you! You've made your question more useful. Oct 12 '13 at 10:43
• Many thanks @Glen_b, I´m learning how to use this awesome tool we have(this forum). I´ll keep your tip in mind when asking new questions. Oct 12 '13 at 10:47

Yes, you can overfit logistic regression models. But first, I'd like to address the point about the AUC (Area Under the Receiver Operating Characteristic Curve): There are no universal rules of thumb with the AUC, ever ever ever.

What the AUC is is the probability that a randomly sampled positive (or case) will have a higher marker value than a negative (or control) because the AUC is mathematically equivalent to the U statistic.

What the AUC is not is a standardized measure of predictive accuracy. Highly deterministic events can have single predictor AUCs of 95% or higher (such as in controlled mechatronics, robotics, or optics), some complex multivariable logistic risk prediction models have AUCs of 64% or lower such as breast cancer risk prediction, and those are respectably high levels of predictive accuracy.

A sensible AUC value, as with a power analysis, is prespecified by gathering knowledge of the background and aims of a study apriori. The doctor/engineer describes what they want, and you, the statistician, resolve on a target AUC value for your predictive model. Then begins the investigation.

It is indeed possible to overfit a logistic regression model. Aside from linear dependence (if the model matrix is of deficient rank), you can also have perfect concordance, or that is the plot of fitted values against Y perfectly discriminates cases and controls. In that case, your parameters have not converged but simply reside somewhere on the boundary space that gives a likelihood of $\infty$. Sometimes, however, the AUC is 1 by random chance alone.

There's another type of bias that arises from adding too many predictors to the model, and that's small sample bias. In general, the log odds ratios of a logistic regression model tend toward a biased factor of $2\beta$ because of non-collapsibility of the odds ratio and zero cell counts. In inference, this is handled using conditional logistic regression to control for confounding and precision variables in stratified analyses. However, in prediction, you're SooL. There is no generalizable prediction when you have $p \gg n \pi(1-\pi)$, ($\pi = \mbox{Prob}(Y=1)$) because you're guaranteed to have modeled the "data" and not the "trend" at that point. High dimensional (large $p$) prediction of binary outcomes is better done with machine learning methods. Understanding linear discriminant analysis, partial least squares, nearest neighbor prediction, boosting, and random forests would be a very good place to start.

• When you say $y$, I guess you mean the proportion of the time that y=1? And not the sum of the number of times that y=1? Oct 7 '13 at 18:35
• That was confusing, p is the number of parameters in the model, I now use $\pi$ for the proportion. Thanks for pointing that out. Oct 7 '13 at 18:49
• @KevinH.Lin It depends on the nature of the question. The more in which you incorporate contextually appropriate knowledge, the better. This would be the underlying prevalence or burden of disease or condition which the model assesses, performance of existing (competing) models, cost-effectiveness tradeoffs, and policies surrounding the adoption of new practices and/or recommendations. Nothing about it is black and white, but like so many things, you need to argue compellingly to convince and reason in favor of an AUC value that you, as the statistician, prespecify. Dec 9 '14 at 19:37
• @KevinH.Lin I don't think any valid answer will be as clear and concise as the one you seem to want. It's like asking, "What car should I buy?" :) I suggest you review articles that have explored AUCs in the pertinent research area that interests you. I have worked largely in risk prediction models for breast cancer and through the works of Tice, Gail, and Barlow among others seen that an AUC of 0.65 is very attractive for population based prediction models that have a prevalence of less than 1-20 incident case per 5,000 person-years at-risk using 7 risk factors having RR btn 1.5 and 3. Dec 9 '14 at 22:12
• @AdamO If there is no "typical" argument, I'd still like to see ANY one good argument. For instance, what are some reasons why 0.65 is a good value in the example you cite? Dec 11 '14 at 8:33

In simple words.... an overfitted logistic regression model has large variance, means decision boundry changes largely for small change in variable magnitude. consider following image the right most one is overfitted logistic model, its decision boundry has large no. of ups and downs while the middel one is just fit it has moderate variance and moderate bias. the left one is underfit it has high bias but very less variance. one more thing_ An overfitted regrresion model have too many features while underfit model has very less no. of features. • Please add reference for the image (actually Andrew Ng's course). Jul 13 '16 at 17:04

You can overfit with any method, even if you fit the whole population (if the population is finite).

There are two general solutions to the problem:

1. penalized maximum likelihood estimation (ridge regression, elastic net, lasso, etc.) and

2. the use of informative priors with a Bayesian model.

When $$Y$$ has limited information (e.g. is binary or is categorical but unordered), overfitting is more severe, because whenever you have low information it is like having a smaller sample size. For example, a sample of size 100 from a continuous $$Y$$ may have the same information as a sample of size 250 from a binary $$Y$$, for the purposes of statistical power, precision, and overfitting. Binary $$Y$$ assumes an all-or-nothing phenomenon and has 1 bit of information. Many continuous variables have at least 5 bits of information.

Is there any model, leave aside logistic regression, that it is not possible to overfit?

Overfitting arises fundamentally because you fit to a sample & not the whole population. Artifacts of your sample can seem like features of the population and they are not and hence overfitting hurts.

It is akin to a question of external validity. Using only the sample you are trying to get a model that gives you the best performance on the real population which you cannot see.

Sure, some model forms or procedures are more likely to overfit than others but no model is ever truly immune from overfitting, is it?

Even out-of-sample validation, regularization procedures etc. can only guard against over-fitting but there's no silver bullet. In fact, if one were to estimate one's confidence in making a real world prediction based on a fitted model one must always assume that some degree of overfitting has indeed happened.

To what extent might vary, but even a model validated on a hold out dataset will rarely yield in-wild performance that matches what was obtained on the hold-out dataset. And overfitting is a big causative factor.

What we do with the Roc to check for overfitting is to separete the dataset randomly in training and valudation and compare the AUC between those groups. If the AUC is "much" (there is also no rule of thumb) bigger in training then there might be overfitting.