Skip to content

feat(machine_learning): Add Binary Logistic Regression classifier - #3228

Open
Rosander0 wants to merge 1 commit into
TheAlgorithms:masterfrom
Rosander0:add-logistic-regression
Open

Rosander0 wants to merge 1 commit into
TheAlgorithms:masterfrom
Rosander0:add-logistic-regression

Conversation

@Rosander0

Copy link
Copy Markdown

Description of Change

This PR adds Binary Logistic Regression to the Machine Learning module—a foundational supervised learning algorithm for binary classification problems.

What it does:

Implements logistic regression using batch gradient descent with numerically stable sigmoid computation
Supports probability prediction, class prediction with adjustable decision threshold, and accuracy scoring
Includes comprehensive Doxygen documentation with mathematical notation for the sigmoid function, binary cross-entropy loss, and gradient descent updates

Why it matters:

Fills a gap in the ML folder (currently has KNN, Adaline, Neural Networks, but no regression-based classifiers)
Complements the existing Linear Regression by showing how to extend it for classification via the sigmoid transformation
Practical for real-world use (spam detection, disease diagnosis, churn prediction) while remaining interpretable and fast to train

Technical details:

Time complexity: O(N × F × I) where N = samples, F = features, I = iterations
Space complexity: O(F) for weights storage
Validates input (binary labels 0/1, feature consistency, size matching)
Includes a self-contained test with synthetic linearly-separable data that achieves 100% training accuracy and demonstrates probability predictions

Testing:

Built-in test creates 8 samples (4 class 0, 4 class 1) in 2D space
Verifies convergence (loss decreases over 500 iterations)
Confirms predictions match true labels and probabilities are calibrated correctly
Validates single-sample and batch prediction modes

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant