257 Commits
Author SHA1 Message Date
Christian Clauss 3dae007c74 More ruff rules ANN for type annotations (#15443) 2026-09-26 17:27:43 +02:00
priya-sundaram-dev f0ab75d0d2 Remove tensorflow/keras files and the keras dependency (#15420)
Per discussion in #15418, these four files are not algorithms (they are
how-to-use scripts wrapping a deep-learning framework) and dragged in the
heavy keras/tensorflow dependency stack:

- computer_vision/cnn_classification.py
- dynamic_programming/k_means_clustering_tensorflow.py
- machine_learning/lstm/lstm_prediction.py
- neural_network/input_data.py (TF MNIST data loader; nothing imports it)

Also removes the now-orphaned machine_learning/lstm/ package (only
__init__.py + sample_data.csv, which served lstm_prediction.py).

Cleanups:
- Drop keras from pyproject.toml dependencies; regenerate uv.lock
  (removes absl-py, h5py, keras, ml-dtypes, namex, optree).
- Remove the pre-release libhdf5-dev install step from build.yml and
  sphinx.yml (it existed only because keras needs hdf5).
- Drop the four stale pytest --ignore entries in build.yml.
- Remove the four DIRECTORY.md entries and the empty Lstm heading.
2026-09-24 04:45:23 +02:00
Priyanshu Mishrapriya-sundaram-devpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>John LawpoyeaChristian Clausscclauss
c3984d3f19 Added Random Forest Regressor as an additional prediction model. (#12767)
* Added Random Forest Regressor as an additional prediction model.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added Random Forest Regressor to main voting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update run.py

* Update run.py

* Update run.py

Used matplotlib to plot actual vs predicted user count, forecast confidence intervals, outlier thresholds from IQR.
Added logging instead of print because in production, print() is not scalable.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update run.py

* Update run.py

* updating DIRECTORY.md

* Apply suggestion from @cclauss

* updating DIRECTORY.md

* updating DIRECTORY.md

* Apply batched suggestions from code review

Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: poyea <poyea@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
2026-09-23 21:45:28 +02:00
Komil-parmarandChristian Clauss 7202e13f82 Add t-SNE implementation and tests for dimensionality reduction (#13337)
* Add t-SNE implementation and tests for dimensionality reduction

Implemented the t-distributed stochastic neighbor embedding (t-SNE) algorithm in dimensionality_reduction.py, including input validation and a test function.

* Fix Ruff linting errors E501 and EM102 in t-SNE implementation

Resolve line length violation (E501) and f-string literal in exception (EM102) by splitting error message and using variable assignment.

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-22 07:35:22 +02:00
Khushi TyagiandChristian Clauss d9027b0346 ty: un-ignore invalid-type-arguments (#15392)
* ty: un-ignore invalid-type-arguments

* Refactor Comparable protocol and improve docstrings

Removed unused __lt__ method from Comparable protocol and updated docstrings for clarity.

* Remove unused total_ordering import

Removed unused import of total_ordering from functools.

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-21 18:27:24 +02:00
Sushanth012 f688e7c5d8 Fix LDA comment grammar (#14800) 2026-09-21 18:13:56 +02:00
Harmanayapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
f363673add Add Ridge Regression to Machine Learning (#12246)
* Fix issue #12108: Added Ridge Regression to Machine Learning

* Added type hints and minor case improvements

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Resolved ruff checks

* Added doctests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Resolved ruff checks

* Resolved mypy checks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Resolved ruff checks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updating DIRECTORY.md

* Comments should not force line wrapping

* updating DIRECTORY.md

* Fix feature scaling variable assignment in predictions

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-19 22:59:02 +02:00
Dinesh Sutharpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
1f27232eac Add regression visualization (#14637)
* Add visualization support for linear regression

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix linting and plotting issues

* Apply ruff auto fixes

* Fix spelling issue

* Update linear_regression.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-16 09:06:03 +02:00
Guo ShuaiandChristian Clauss d740bb00fb Add Gaussian negative log likelihood loss algorithm (#11263)
* Add Gaussian negative log likelihood loss algorithm

* Fix boolean conversion in Gaussian NLL loss example

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-16 00:55:05 +02:00
Guo ShuaiandChristian Clauss 5ed60e71c8 Add the sparse categorical cross-entropy loss (#11250)
* Add sparse categorical cross entropy loss algorithm

* Update loss_functions.py

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-16 00:45:10 +02:00
3e5b596d16 Add connectionist temporal classification (CTC) loss algorithm (#11240)
* Add connectionist temporal classification (CTC) loss algorithm

* Update loss_functions.py

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-16 00:34:10 +02:00
Sep Aminianpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclausssephml
624d2075f9 added multi armed bandit problem with three strategies to solve it (#12668)
* added multi arm bandit alg with three strategies to solve it

* added doctest tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* corrected test cases

* added return type hinting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* return typehint for test func updated

* fixed variable name k

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixed formatting

* fix1

* fixed issues with mypy, ruff

* updating DIRECTORY.md

* Address Copilot review comments on MAB PR

- Cast rng.integers() results to Python int in EpsilonGreedy and
  RandomStrategy select_arm, fixing doctest flakiness from np.int64
- Fix grammar in module docstring and RandomStrategy docstring
- Add missing doctest for Bandit.__init__
- Split test_mab_strategies into a real deterministic assertion-based
  test and a separate demo_mab_strategies for the stochastic plot
- Revert DIRECTORY.md to upstream (auto-generated, out of scope here)

* updating DIRECTORY.md

* updating DIRECTORY.md

* updating DIRECTORY.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Co-authored-by: sephml <sephml@users.noreply.github.com>
2026-09-15 19:20:58 +02:00
Jeel GajeraJeel Gajerapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
7428666632 Add: Ordinary Least Squares Regression Algorithm (#10800)
* Add: Ordinary Least Squares Regression Algorithm

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: typos

* fix: descriptive names

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Change intercept output to float in examples

* Update ordinary_least_squares_regression.py

---------

Co-authored-by: Jeel Gajera <jeelgajera00@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-14 19:31:21 +02:00
Prerit Aryapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
3f8772c07a Add DBSCAN clustering algorithm in machine_learning/ (#14851)
* Add DBSCAN clustering algorithm in machine_learning/

* Fix logic order in dbscan: check cluster membership before assigning

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-14 13:09:05 +02:00
Rahul Singh Rajpurohitandpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> b0e80a41ed Add multinomial Naive Bayes text classification example (#14665)
* Add multinomial Naive Bayes text classification example

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review feedback for Naive Bayes text Classifier

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-14 06:53:40 +02:00
Aryan Neogi 423eb9183a Add RMSprop optimizer to machine_learning (#14733) 2026-09-14 06:49:25 +02:00
Prerit Aryaandpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> c986722782 Add Mean Shift clustering algorithm in machine_learning/ (#14858)
* Add Mean Shift clustering algorithm in machine_learning/

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename lambda variable for clarity in mean_shift.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-14 06:45:45 +02:00
Md Ruman Islamandpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> bd7de3b47a Add Gaussian Mixture Model (GMM) Algorithm for Clustering (#13637)
* Add Gaussian Mixture Model (GMM) algorithm

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add trailing newline and finalize Gaussian Mixture Model implementation

* Fix Mypy type alias issue for FloatArray

* Use modern 'type' syntax for FloatArray to satisfy Ruff UP040

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-14 06:37:17 +02:00
Sanjam Wadhwaandpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> ad99d5e3e4 Add Q-Learning algorithm implementation with epsilon-greedy policy an… (#13402)
* Add Q-Learning algorithm implementation with epsilon-greedy policy and grid world demo

* Add Q-Learning algorithm implementation with epsilon-greedy policy and grid world demo code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* bug fixes and linting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* cls

* bug fix and hints

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-14 06:06:53 +02:00
Sanskar ModiandChristian Clauss a23264cca9 added mini batch gradient descent algo in ml dir (#13026)
* added mini batch gradient descent algo in ml dir

* updated code

* updated code quality

* updated docs

* Refactor parameter documentation in mini_batch_gradient_descent.py

Updated parameter documentation format in mini_batch_gradient_descent.py.

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-14 06:05:19 +02:00
LuisMelendez 33658c233f Update and rename k_nearest_neighbours.py to k_nearest_neighbors.py (#13085) 2026-09-14 05:48:41 +02:00
Christian Clauss 0525ef5da8 ruff rule ANN202 missing-return-type-private-function (#15298)
* ruff rule ANN202 missing-return-type-private-function

* ruff rule ANN202 missing-return-type-private-function
2026-09-12 21:47:08 +02:00
Christian Clauss 0da45b148a ruff rule ANN204 missing-return-type-special-method (#15300) 2026-09-12 21:35:04 +02:00
Christian Claussandcclauss 7bd1e983c3 ruff rules RET for return statements (#15301)
* updating DIRECTORY.md

* ruff rules RET for return statements

---------

Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-12 21:33:52 +02:00
priya-sundaram-dev 611418cfb2 machine_learning: add numeric doctests to gradient_descent (#15286) 2026-09-12 11:18:13 +02:00
priya-sundaram-dev 3e34e8ef75 machine_learning: pin numeric output of k_means_clust with doctests (#15285) 2026-09-12 02:12:26 +02:00
e548737115 Implement K-Medoids Clustering Algorithm #13488 (#13510)
* Added k_medoids algorithm

* updating DIRECTORY.md

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-12 01:38:47 +02:00
somrita-banerjeepre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
102078a50a Add vectorized implementations of Linear Regression using Gradient Descent (#13221)
* Add naive and vectorized implementations of Linear Regression using Gradient Descent

* Add references section to docstrings in linear regression implementations

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor function signatures for improved readability in linear regression implementation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor function signatures for improved readability in linear regression implementation

* Update README sections for dataset inputs and usage instructions in linear regression implementations

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add doctests for dataset collection and gradient descent functions

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor imports and improve README formatting in linear regression scripts

* fix doctests

* Remove linear regression naive implementation script

* Refactor docstring and improve script documentation for clarity

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix formatting in gradient_descent doctest and streamline main function call

* fix doctest

* updating DIRECTORY.md

* Change httpx to httpx2 and update docstring

Updated import from httpx to httpx2 and modified docstring for dataset return type.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-12 01:27:12 +02:00
kdt523 b96d9d90b1 Feature federated learning (#13615)
* Add_Federated_Averaging_FedAvg_module_with_doctests

* Update_FedAvg_doctests

* Rename_normalize_weights_param_to_num_clients

* Fix_ruff_issues_in_FedAvg_module
2026-09-12 00:59:19 +02:00
BHUMIKA KADU✨andkadubhumika 1eb3c71d7f Fix invalid parameter default (#15281)
* updating DIRECTORY.md

* ty: fix invalid parameter defaults

* Fix invalid parameter defaults

---------

Co-authored-by: kadubhumika <kadubhumika@users.noreply.github.com>
2026-09-11 18:40:07 +02:00
Louis Deconinck b6224ec5ed fix: return sum of squared errors (#15272) 2026-09-11 18:21:42 +02:00
Vedansh Tyagi a6ee9b7bc5 Fixes #10 (#13355) 2026-09-10 20:17:11 +02:00
bf57384133 fix:Added condition array for filtering 0 values (#12262)
Co-authored-by: evan.zhang5 <evan.zhang5@nio.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-10 08:52:32 +02:00
Christian Claussandcclauss 3725b917aa pre-commit: Add zizmor and replace prettier with rumdl (#15236)
* pre-commit: Add zizmor and replace prettier with rumdl

* updating DIRECTORY.md

---------

Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-09 09:55:19 +01:00
BHUMIKA KADU✨kadubhumikapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
636dd57af7 Fix ty invalid assignment (#15222)
* Fix ty invalid assignment diagnostics

* updating DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix unused typing import

* Fix gradient accumulation type handling

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix automatic differentiation gradient dtype handling

---------

Co-authored-by: kadubhumika <kadubhumika@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-08 17:57:46 +02:00
priya-sundaram-dev 30f321fa1f Remove xgboost demos and dependency (#15219)
Drop machine_learning/xgboost_classifier.py and
machine_learning/xgboost_regressor.py. Both were thin "how-to-use"
wrappers around sklearn's XGBClassifier/XGBRegressor rather than
from-scratch implementations, and the classifier's only doctest was
already disabled (# THIS TEST IS BROKEN!!), so it was never exercised
in CI.

xgboost is one of the heaviest compiled dependencies in the tree (large
wheel, needs OpenMP/libgomp at runtime, no free-threaded wheel yet), and
gradient boosting is already implemented from scratch in
machine_learning/gradient_boosting_classifier.py and
gradient_boosting_regressor.py, so no algorithm coverage is lost.

Removes the xgboost dependency from pyproject.toml, its (and its
xgboost-only transitive dep nvidia-nccl-cu13) entries from uv.lock, and
the two DIRECTORY.md links.

Refs #15081
2026-09-07 09:49:06 +02:00
priya-sundaram-dev 35b7074d2d Re-enable five disabled algorithms and the perceptron (#15208)
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 #8029; perceptron follow-up to #15206.
2026-09-06 18:52:09 +02:00
duuanpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
181175e9d4 Add implementation of the multi-layer perceptron classifier from scratch (#12756)
* add a code file of the multi-layer perceptron classifier from scrach

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Delete tqdm in multilayer_perceptron_classifier_from_scratch.py

* Update multilayer_perceptron_classifier_from_scratch.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update multilayer_perceptron_classifier_from_scratch.py

add a code file of the multi-layer perceptron classifier from scrach

* Correct errors in multilayer_perceptron_classifier_from_scratch.py

* Delete machine_learning/multilayer_perceptron_classifier.py

* Rename multilayer_perceptron_classifier_from_scratch.py

* Apply suggestion from @cclauss

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-06 18:11:11 +02:00
priya-sundaram-devandpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> bfa655ecea deps: migrate from httpx to httpx2 (pydantic's maintained fork) (#15192)
* deps: migrate from httpx to httpx2 (pydantic's maintained fork)

Mechanical rename of httpx -> httpx2 (API-compatible fork of httpx 0.28.1):
pyproject.toml deps, PEP 723 inline-script headers, and all import/call sites.
Excludes uv.lock (the keeper's allow-list rejects .lock files); the lock
refresh needs a separate maintainer-merged PR.

Refs #15081

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* deps: drop tweepy + migrate remaining requests refs to httpx2

- maths/allocation_number.py: docstring example uses httpx2, not requests
- web_programming/get_imdbtop.py.DISABLED: import httpx2 instead of requests
- remove web_programming/get_user_tweets.py.DISABLED (a Twitter API how-to,
  not an algorithm) and drop the tweepy dependency that was its only user and
  the last high-level dep pulling in requests
- uv.lock intentionally untouched (keeper allow-list)

Refs #15081

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-05 09:26:45 +02:00
priya-sundaram-dev 659b468cab ci: reduce pytest --ignore list in build.yml (re-enable local_weighted_learning) (#15118)
* ci: un-ignore local_weighted_learning doctests in build.yml

machine_learning/local_weighted_learning/local_weighted_learning.py only
imports numpy and matplotlib (both already project dependencies) and its
5 doctests pass headlessly. Removing it from the pytest --ignore list so
the module is covered by CI again.

* fix(local_weighted_learning): use a well-conditioned bandwidth in doctests

The doctests used tau=0.6 on data with feature values ~17-25, so the
Gaussian weights underflowed to ~0 (e.g. 8e-118, 1e-177). That made
X\u1d40WX numerically singular (cond ~5.6e18), so its inverse - and the
resulting predictions - were nondeterministic across numpy/BLAS builds.
That is why the module was on the pytest --ignore list; on the CI numpy
the first prediction came out 0.0 instead of the documented 1.07.

Switch the doctests to tau=5 (cond ~2e2), matching the bandwidth the
module's own main() already uses, and round the outputs so they are
stable across platforms. Deterministic now; removed from --ignore.
2026-08-30 09:04:20 +02:00
priya-sundaram-dev f3f599a617 Use typing.Self in automatic_differentiation (drop typing_extensions) (#15114)
`machine_learning/automatic_differentiation.py` was the only module
importing `Self` from `typing_extensions`, behind a `# noqa: UP035`.
Since the repo requires Python >=3.14, `typing.Self` (added in 3.11)
is always available, so import it from the stdlib and drop the noqa.

### Describe your change:

* [x] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
* [ ] Documentation change?

### Checklist:

* [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
* [x] This pull request is all my own work -- I have not plagiarized.
* [x] I know that pull requests will not be merged if they fail the automated tests.
* [x] This PR only changes one algorithm file. If not, please split into separate PRs.
* [x] All new Python files are placed inside an existing directory.
* [x] All filenames are in all lowercase characters with no spaces or dashes.
* [x] All functions and variable names follow Python naming conventions.
* [x] All function parameters and return values are annotated with Python type hints.
* [x] All functions have doctests that pass the automated testing.
* [x] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
2026-08-29 01:03:27 +02:00
Ali Satwat KhanChristian Clausspre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
eea1bacfe0 fix: raise ValueError in encode() for non-lowercase input (#14936)
* fix: raise ValueError in encode() for non-lowercase input

encode() previously accepted uppercase letters, digits, and other
non-lowercase characters silently, producing incorrect/out-of-range
values (e.g. negative numbers for uppercase letters) instead of
failing. Add input validation using str.islower() and str.isalpha()
to raise a ValueError when the input isn't purely lowercase a-z.
Added a doctest covering the new error case.

* resolved doctest

* Fix Ruff 0.16 lint failures

* Enhance encode function error handling examples

Update error handling in encode function to include examples for mixed case and invalid characters.

* Fix indentation in test_cancer_data function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-07-31 18:07:20 +02:00
John Law e333ddb852 chore: Fix ruff build failures (#14347) 2026-03-07 21:29:05 +01:00
João Netopre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Maxim Smolskiy
154cd3e400 feat: optimizing the prune function at the apriori_algorithm.py archive (#12992)
* feat: optimizing the prune function at the apriori_algorithm.py archive

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: fixing the unsorted importing statment

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: fixing the key structure to a tuple that can be an hashable structure

* Update apriori_algorithm.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update apriori_algorithm.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
2025-10-20 01:21:00 +03:00
Harsh PathakandMaxim Smolskiy c79034ca21 Update logical issue in decision_tree.py (#13303)
Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
2025-10-17 04:00:44 +03:00
Khansa435Christian Clausspre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
709c18ee9f Add t stochastic neighbour embedding using Iris dataset (#13476)
* Added t-SNE with Iris dataset example

* Added t-SNE with Iris dataset example

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated with descriptive variables

* Add descriptive variable names

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add Descriptive Variable names

* Adding Descriptive variable names

* Update machine_learning/t_stochastic_neighbour_embedding.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update machine_learning/t_stochastic_neighbour_embedding.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Improved line formatting

* Adding URL for t-SNE Wikipedia

* Apply suggestion from @cclauss

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2025-10-14 13:14:22 +02:00
Christian Clauss 9372040da9 Test on Python 3.14 (#12710) 2025-10-07 18:23:37 +02:00
Christian Claussandpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> 63180d7e24 pre-commit autoupdate 2025-09-11 (#12963)
* pre-commit autoupdate 2025-09-11

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-09-13 01:56:14 +03:00
lorenzo30salgadoandMaxim Smolskiy e3a263c1ed Adding a 3D plot to the k-means clustering algorithm (#12372)
* Adding a 3D plot to the k-means clustering algorithm

* Update k_means_clust.py

* Update k_means_clust.py

---------

Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
2025-08-30 23:58:54 +03:00
Christian ClaussLim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com>cclausspre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
a2fa32c7ad Lukazlim: Replace dependency requests with httpx (#12744)
* Replace dependency `requests` with `httpx`

Fixes #12742
Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com>

* updating DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com>
Co-authored-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-14 04:42:11 +03:00