Skip to content

Re-enable five disabled algorithms and the perceptron - #15208

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:reenable-disabled-algos
Sep 6, 2026
Merged

Re-enable five disabled algorithms and the perceptron#15208
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:reenable-disabled-algos

Conversation

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Re-enables the four disabled scikit-learn ML examples and the neural-network perceptron, as requested in #8029, and modernizes them so they import and run cleanly on current scikit-learn and pass the doctest CI. (Perceptron is the follow-up discussed in #15206.)

Why they were failing

These files had drifted against scikit-learn's API and could no longer be imported by the --doctest-modules test run:

  • sklearn.metrics.plot_confusion_matrix was removed in scikit-learn 1.2 (replaced by ConfusionMatrixDisplay).
  • sklearn.datasets.load_boston was removed in scikit-learn 1.2 (for ethical reasons).

Changes

machine_learning/gaussian_naive_bayes.py, machine_learning/random_forest_classifier.py

  • Swap plot_confusion_matrix(...)ConfusionMatrixDisplay.from_estimator(...).
  • Remove the artificial time.sleep() calls.

machine_learning/gradient_boosting_regressor.py, machine_learning/random_forest_regressor.py

  • Swap the removed Boston dataset → the bundled load_diabetes dataset, so the examples run offline with no download.

neural_network/perceptron.py

  • Use a dedicated seeded random.Random instance instead of the global random state → training is reproducible and thread-safe under the parallel test runner.
  • Cap training at epoch_number so it always terminates, even on non-linearly-separable data (was an unbounded while True).
  • training() / sort() now return their results instead of printing, per the contribution guidelines; doctests updated accordingly.

Checklist

  • python3 -m doctest neural_network/perceptron.py passes.
  • ruff check and ruff format --check pass on all five files.
  • The heavy demo code stays under if __name__ == "__main__":, so the doctest CI only imports the modules (no model training during collection).

The ML examples are thin scikit-learn demos; I kept their structure intact and limited changes to what's needed to make them import/run again. Happy to iterate if you'd prefer a different dataset or a deeper rewrite of any of them.

Re-enable the four scikit-learn machine-learning examples and the
neural-network perceptron that had been disabled (renamed to
.broken.txt / .DISABLED), and modernize them so they import and run
cleanly on current scikit-learn and pass the doctest CI:

machine_learning/gaussian_naive_bayes.py
machine_learning/random_forest_classifier.py
  - Replace the removed sklearn.metrics.plot_confusion_matrix with
    ConfusionMatrixDisplay.from_estimator (removed in scikit-learn 1.2).
  - Drop the artificial time.sleep() calls.

machine_learning/gradient_boosting_regressor.py
machine_learning/random_forest_regressor.py
  - Replace the removed load_boston dataset (removed in scikit-learn
    1.2 for ethical reasons) with the bundled load_diabetes dataset so
    the examples run offline.
  - Avoid an unused-variable lint (RUF059).

neural_network/perceptron.py
  - Use a dedicated seeded random.Random instance instead of the global
    random state, so training is reproducible and thread-safe under the
    parallel test runner.
  - Cap training at epoch_number epochs so it always terminates even on
    non-linearly-separable data (previously an unbounded while True).
  - Have training() and sort() return their results instead of printing,
    per the contribution guidelines, and update the doctests accordingly.

Requested by @cclauss in TheAlgorithms#8029; perceptron follow-up to TheAlgorithms#15206.
@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Sep 6, 2026
@priya-sundaram-dev priya-sundaram-dev mentioned this pull request Sep 6, 2026
14 tasks
@cclauss
cclauss enabled auto-merge (squash) September 6, 2026 16:51

@cclauss cclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A-w-e-s-o-m-e!!!

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 6, 2026
@cclauss
cclauss merged commit 35b7074 into TheAlgorithms:master Sep 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants