TheAlgorithms / TheAlgorithms/Java

[FEATURE REQUEST] Add Perceptron binary classifier

Abierto
#7,599 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Java
Estrellas
66.3k
Forks
21.3k
Merge medio
16 h 57 min
PR fusionados (30 d)
23

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza leyendo las implementaciones existentes de LinearRegression, KNearestNeighbors y MultinomialNaiveBayesClassifier en src/main/java/com/thealgorithms/machinelearning y, después, revisa el pull request histórico para obtener contexto. Añade Perceptron.java con pruebas que sigan las convenciones del repositorio; se considera terminado cuando funcionen los datos separables, las predicciones sobre datos no vistos y por lotes, los errores antes del ajuste y ante entradas no válidas, y el comportamiento documentado para datos no separables.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
machine-learning
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bien especificado
Aptitud para principiantes
78/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.