Skip to content

Add Perceptron binary classifier - #7601

Open
Th-Shivam wants to merge 2 commits into
TheAlgorithms:masterfrom
Th-Shivam:add-perceptron
Open

Add Perceptron binary classifier#7601
Th-Shivam wants to merge 2 commits into
TheAlgorithms:masterfrom
Th-Shivam:add-perceptron

Conversation

@Th-Shivam

Copy link
Copy Markdown
Contributor

Summary

Adds a binary Perceptron classifier to com.thealgorithms.machinelearning. The implementation uses deterministic zero initialization, an explicit bias term, configurable learning rate and epoch limit, input validation, single and batch prediction, defensive weight access, and convergence metadata.

Tests

  • AND toy dataset converges and predicts training samples correctly.
  • Unseen and batch predictions are covered.
  • XOR non-separable data stops at the configured epoch limit without reporting convergence.
  • Re-fitting, defensive copies, pre-fit access, invalid hyperparameters, invalid training data, and invalid prediction data are covered.

Verification

  • Java 21-compatible compilation passed.
  • Direct JUnit Platform execution: 11 tests passed.
  • git diff --check passed.
  • Full Maven/CI checks could not be run in this environment because Maven and clang-format are not installed; upstream CI should run them.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • The new algorithm has a Wikipedia URL in its comments.
  • The new algorithm includes a corresponding test class.
  • New code follows the repository formatting style.

Closes #7599

@codecov-commenter

codecov-commenter commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.04%. Comparing base (1f08afb) to head (ff0842d).

Files with missing lines Patch % Lines
.../com/thealgorithms/machinelearning/Perceptron.java 93.75% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7601      +/-   ##
============================================
+ Coverage     81.01%   81.04%   +0.03%     
- Complexity     7740     7776      +36     
============================================
  Files           825      826       +1     
  Lines         24594    24674      +80     
  Branches       4810     4827      +17     
============================================
+ Hits          19925    19998      +73     
- Misses         3906     3909       +3     
- Partials        763      767       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Th-Shivam
Th-Shivam marked this pull request as ready for review September 10, 2026 06:53
Copilot AI lite review requested due to automatic review settings September 10, 2026 06:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

[FEATURE REQUEST] Add Perceptron binary classifier

3 participants