TheAlgorithms / TheAlgorithms/Java

[FEATURE REQUEST] Add Perceptron binary classifier

未關閉
#7,599 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Java
星號
66.3k
分支
21.3k
平均合併
16 小時 57 分鐘
30 天內合併 PR
23

描述

What would you like to Propose?

Add a Perceptron classifier to src/main/java/com/thealgorithms/machinelearning. The Perceptron is the simplest neural network and would provide an educational binary linear-classification algorithm alongside the existing LinearRegression, KNearestNeighbors, and MultinomialNaiveBayesClassifier implementations.

Issue details

Algorithm name: Perceptron

Problem statement: Given a set of feature vectors and binary class labels, learn a linear decision boundary using the Perceptron learning rule, then classify previously unseen samples. The implementation should make the bias term explicit and document that convergence is guaranteed only for linearly separable data.

Suggested scope:

  • Add Perceptron.java in the machinelearning package.
  • Use only the Java standard library; no external machine-learning dependency is needed.
  • Provide a small, clear API for fitting, predicting one sample, and predicting a batch.
  • Support configurable learning rate and maximum epochs, with deterministic zero-weight and zero-bias initialization.
  • Validate null or empty data, inconsistent feature dimensions, invalid labels, and invalid hyperparameters with clear exceptions.
  • Document the update rule, label convention, and limitations in Javadoc.

Acceptance tests:

  • Train on a linearly separable toy dataset such as AND or OR and classify all training samples correctly.
  • Verify predictions for unseen samples and batch prediction.
  • Verify that prediction before fitting fails clearly.
  • Verify invalid labels, mismatched dimensions, null or empty input, and invalid learning-rate or epoch values.
  • Include a non-separable-data test that checks documented behavior, such as stopping after the epoch limit without claiming convergence.

A historical pull request, #187, attempted a Perceptron implementation in 2018, but there is no current implementation in the package. This request is for a current Java 21 implementation with tests that follow the repository conventions.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先閱讀 src/main/java/com/thealgorithms/machinelearning 下現有的 LinearRegression、KNearestNeighbors 和 MultinomialNaiveBayesClassifier 實作,然後檢視歷史 pull request 以了解背景。依照 repository 慣例新增 Perceptron.java 及其測試;當可分資料、對未見資料的預測與批次預測、擬合前失敗與無效輸入失敗,以及文件中說明的不可分資料行為都能正常運作時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
machine-learning
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
活躍
描述清晰度
描述清楚
新手友好度
78/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。