Overview

Logistic Regression is a supervised learning algorithm used for classification tasks, despite having “regression” in its name. It predicts the probability that an instance belongs to a particular class.

Binary Logistic Regression

See Logistic Regression - Binary.

Multiclass Logistic Regression

See Logistic Regression - Multiclass.

Advantages

  • Simple and interpretable: Coefficients show feature importance
  • Probabilistic output: Provides confidence scores
  • Fast training and prediction: Efficient for large datasets
  • No hyperparameters (basic version)
  • Works well with linearly separable data
  • Less prone to overfitting than more complex models (with regularization)

Disadvantages

  • Assumes linear decision boundary: Can’t capture complex patterns
  • Sensitive to outliers: Extreme values can influence coefficients
  • Requires feature engineering for non-linear relationships
  • Multicollinearity issues: Correlated features can be problematic
  • Not suitable for complex patterns (use tree-based or neural networks instead)

Regularization

See Logistic Regression - Regularization.

Assumptions

  1. Binary or ordinal outcome (for binary logistic regression)
  2. Linear relationship between log-odds and features
  3. Independence of errors (observations are independent)
  4. No multicollinearity among features
  5. Large sample size for stable estimates

Evaluation Metrics

  • Accuracy: Overall correctness
  • Precision: Of predicted positives, how many are correct?
  • Recall: Of actual positives, how many did we find?
  • F1-Score: Harmonic mean of precision and recall
  • AUC-ROC: Area under ROC curve
  • Average Precision: Area under Precision-Recall curve

Hyperparameters

ParameterDescriptionCommon Values
CInverse of regularization strength0.01, 0.1, 1, 10, 100
penaltyRegularization type’l1’, ‘l2’, ‘elasticnet’, ‘none’
solverOptimization algorithm’lbfgs’, ‘liblinear’, ‘saga’
max_iterMaximum iterations100, 1000, 10000
class_weightWeight for imbalanced classesNone, ‘balanced’, dict

When to Use

Use Logistic Regression when:

  • Need interpretable model (coefficients show feature importance)
  • Decision boundary is roughly linear
  • Need probability estimates
  • Dataset is not too large
  • Baseline model for comparison
  • Text classification with bag-of-words

Avoid Logistic Regression when:

  • Highly non-linear relationships
  • Many interaction terms needed
  • Very high-dimensional data (use regularized version)
  • Complex patterns (use tree-based or neural networks)

Implementation Example

See Logistic Regression - Implementation Example.

Logistic Regression Vs Other Algorithms

AlgorithmDecision BoundarySpeedInterpretability
Logistic RegressionLinearFastHigh
SVMLinear/Non-linearMediumMedium
Decision TreeNon-linear (axis-aligned)FastHigh
Random ForestNon-linearMediumMedium
Neural NetworkNon-linearSlowLow
[[K Nearest NeigbourKNN]]Non-linearSlow (prediction)

Practical Considerations

  1. Scale features: Use StandardScaler or MinMaxScaler
  2. Handle imbalanced data: Use class_weight='balanced' or resampling
  3. Check linearity: Plot log-odds vs features
  4. Feature engineering: Create polynomial features if needed
  5. Regularization: Always use for high-dimensional data
  6. Cross-validation: Tune C parameter
  7. Interpret coefficients: Positive = increases probability, negative = decreases

References