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 摘要。