Re-enable five disabled algorithms and the perceptron - #15208
Merged
cclauss merged 1 commit intoSep 6, 2026
Conversation
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.
Merged
14 tasks
cclauss
enabled auto-merge (squash)
September 6, 2026 16:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-modulestest run:sklearn.metrics.plot_confusion_matrixwas removed in scikit-learn 1.2 (replaced byConfusionMatrixDisplay).sklearn.datasets.load_bostonwas removed in scikit-learn 1.2 (for ethical reasons).Changes
machine_learning/gaussian_naive_bayes.py,machine_learning/random_forest_classifier.pyplot_confusion_matrix(...)→ConfusionMatrixDisplay.from_estimator(...).time.sleep()calls.machine_learning/gradient_boosting_regressor.py,machine_learning/random_forest_regressor.pyload_diabetesdataset, so the examples run offline with no download.neural_network/perceptron.pyrandom.Randominstance instead of the globalrandomstate → training is reproducible and thread-safe under the parallel test runner.epoch_numberso it always terminates, even on non-linearly-separable data (was an unboundedwhile True).training()/sort()now return their results instead of printing, per the contribution guidelines; doctests updated accordingly.Checklist
python3 -m doctest neural_network/perceptron.pypasses.ruff checkandruff format --checkpass on all five files.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.