Why does an unbalanced sample matter when doing logistic regression?

Why does an unbalanced sample matter when doing logistic regression?

For logistic regression models unbalanced training data affects only the estimate of the model intercept (although this of course skews all the predicted probabilities, which in turn compromises your predictions).

Why are minority classes imbalanced in logistic regression?

The problem is not that the classes are imbalanced per se, it is that there may not be sufficient patterns belonging to the minority class to adequately represent its distribution. This means that the problem can arise for any classifier (even if you have a synthetic problem and you know you have the true model), not just logistic regression.

When to use a balanced sample to make predictions?

Pick a nice balanced sample and then correct the intercept to take into account the fact that you’ve selected on the dependent variable to learn more about rarer classes than a random sample would be able to tell you. On a related but distinct topic: Don’t forget that you should be thresholding intelligently to make predictions.

How are probabilities of a logistic regression model calibrated?

In general, scores returned by machine learning models are not necessarily well-calibrated probabilities (see my post on ROC space and AUC).   The probability estimates from a logistic regression model (without regularization) are partially calibrated, though.

How to calculate weighted logistic regression for imbalanced dataset?

Weights associated with classes in the form {class_label: weight}. If not given, all classes are supposed to have same weight value. With weighted-LG, Area-Under-Curve (AUC) increased drastically from 0.7412 to 0.8802.

When does down sampling change logistic regression coefficients?

Does down-sampling change logistic regression coefficients? If I have a dataset with a very rare positive class, and I down-sample the negative class, then perform a logistic regression, do I need to adjust the regression coefficients to reflect the fact that I changed the prevalence of the positive class?

How to deal with imbalanced datasets in regression?

There are several better-known techniques for dealing with imbalanced datasets including undersampling, data augmentation with the synthetic minority oversampling technique (SMOTE), and weighting the samples by class.

How to use default weights in logistic regression?

After above test-train split, lets build a logistic regression with default weights. For minority class, above model is able to predict 14 correct out of 29 samples. For majority class, model got only one prediction wrong. Model is not doing a good job in predicting minority class.

How to rebalance sklearn with unbalanced classes?

Not all classifiers in sklearn support this, but some do. Check the docstrings. Also you can rebalance your dataset by randomly dropping negative examples and / or over-sampling positive examples (+ potentially adding some slight gaussian feature noise).