Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

Pre-release

This release is a pre-release and may not be stable for production use.

mlxlearn

Classical machine learning on Apple silicon, accelerated with MLX, with a scikit-learn compatible API.

mlxlearn is not officially associated with scikit-learn or PROBABL, nor with Apple.

mlxlearn has two layers.

Layer 1 — the library. Explicit imports, typed solver configuration and state, strict errors, eager fit, no mutation of scikit-learn, no data-keyed caches:

from mlxlearn.neighbors import KNeighborsClassifier

clf = KNeighborsClassifier(n_neighbors=5).fit(X_train, y_train)
y_pred = clf.predict(X_test)

Layer 2 — the patching shell. A thin adapter that points scikit-learn's own names at Layer 1 estimators, so existing code — including code an LLM generated against the scikit-learn API — runs accelerated without being edited:

from mlxlearn import patch_sklearn
patch_sklearn()

from sklearn.svm import SVC          # now resolves to the accelerated class

The numerical library is fully usable and fully tested with the patching mechanism absent.

Status

0.1.0a2 — alpha. The API may change. See CHANGELOG.md.

Estimator Status
mlxlearn.neighbors.NearestNeighbors 0.1.0
mlxlearn.neighbors.KNeighborsClassifier 0.1.0
mlxlearn.neighbors.KNeighborsRegressor 0.1.0
mlxlearn.linear_model.LogisticRegression 0.1.0
mlxlearn.svm.SVC (exact) 0.1.0
LinearRegression, Ridge, PCA, KMeans, DBSCAN, TSNE planned, 0.2.x
SVR, NuSVR, NuSVC deferred — will not ship until they implement the true objective
tree ensembles out of scope

Requirements

  • macOS on Apple silicon (arm64)
  • Python 3.10 – 3.13
  • scikit-learn ≥ 1.7, MLX ≥ 0.29

Python 3.10 is supported with scikit-learn 1.7.x; scikit-learn 1.8+ requires Python ≥ 3.11. CI tests only valid pairs — see docs/support_matrix.md.

Install

pip install mlx-learn

0.1.0a2 ships as a pure-Python wheel — no compiler, no build step, no ABI matrix.

Import-order semantics

Patching replaces attributes on scikit-learn modules. Attribute access (sklearn.svm.SVC) therefore resolves to the mlxlearn class whether import sklearn happened before or after patch_sklearn().

Symbols captured before patching are local bindings and cannot be rebound:

from sklearn.svm import SVC     # binds the stock class into your namespace
patch_sklearn()                 # cannot reach back and change SVC
SVC()                           # still the stock class

That is Python name binding, not a bug in mlxlearn. The supported pattern is patch-first. patch_sklearn() is idempotent, and unpatch_sklearn() fully restores scikit-learn.

When mlxlearn falls back

Layer 1 raises a precise error when it cannot honor a request. Layer 2 falls back to stock scikit-learn instead — but only for capability mismatches (sparse input, an unsupported parameter, an unsupported dtype), never to hide a bug:

Situation Direct import Patched
Capability mismatch precise MLXLearnError falls back, warns once per class, records diagnostics
Problem below the measured crossover internal CPU path dispatches to scikit-learn
Invalid user input sklearn-equivalent validation error scikit-learn's own exception, unmasked
Unexpected MLX runtime failure raises raises — never silently rerun on scikit-learn

Set the policy with fallback_policy="warn" | "raise" | "silent". Diagnostics are recorded in every mode:

import mlxlearn

with mlxlearn.config_context(fallback_policy="raise"):
    ...                                     # any capability fallback becomes an error

mlxlearn.get_last_backend_event()           # what the last fit/predict actually did
mlxlearn.get_backend_diagnostics()          # everything recorded this session

Sticky backend. The backend is chosen during fit and recorded as estimator._execution_backend_ ("mlx", "cpu", or "sklearn"). Every subsequent predict / predict_proba / transform / kneighbors uses the backend the model was fitted with. A model fitted on MLX can never wander into scikit-learn inference with incompatible state. A new fit clears state and may pick a different backend.

Configuration

The public surface is deliberately small:

mlxlearn.set_config(
    device="auto",              # "auto" | "gpu" | "cpu"
    fallback_policy="warn",     # "warn" | "raise" | "silent"
    output_type="numpy",        # 0.1.0: NumPy in, NumPy out
    deterministic=True,
    random_state=0,
    diagnostics=True,
)

Crossover thresholds, block sizes, and solver tuning are private, typed, and overridable only through MLXLEARN_* environment variables for CI and debugging. They are not part of the public API.

Performance

"Never slower than scikit-learn" is the design goal. The shipped gate is measurable: on each benchmarked workload class, patched dispatch shows no statistically significant regression against stock scikit-learn. Crossover points are measured per algorithm and per operation, published in docs/benchmarks.md, and wired into the dispatch thresholds — small problems are handed to scikit-learn on purpose.

What that means in practice for 0.1.0a2, on an M4 Max:

Neighbor queries 2.9×–17× from ~250 samples up. This is the reason to use mlxlearn.
Neighbor fit 0.17×–0.36×. mlxlearn uploads to the device; scikit-learn stores a reference. The first query repays it several times over.
SVC 2.93× on wide data (4 000 × 256, rbf), but slower than LIBSVM on narrow data — 0.47× at 4 000 × 32, worse below. kernel="linear" never uses MLX. Width decides, and patched dispatch routes accordingly.
LogisticRegression Slower than scikit-learn below 1 024 features, by a lot. The crossover is set high so patched dispatch hands those to scikit-learn; see docs/benchmarks.md for why and what would change it.

Reproduce them:

python -m benchmarks.run --profile smoke

Precision

MLX computes in float32 on the GPU. mlxlearn's parity tests are written to float32 tolerances, and the cases where float32 makes strict scikit-learn equivalence impossible are enumerated — not waved away — in docs/fp32_policy.md.

Development

pip install -e ".[dev]"
pytest

Contributor rules, the estimator gate checklist, and the compliance checks are in docs/development.md.

Provenance

mlxlearn succeeds a private research fork of an Intel-maintained scikit-learn accelerator. That history is not carried here: this repository was bootstrapped from an audited allowlist, and no source file was copied. The audit, the recorded behavioral baseline of the ancestor, and the authorship attestation are in phase0/. Full lineage, disclaimers, and third-party notices are in ACKNOWLEDGMENTS.md and THIRD_PARTY_NOTICES.md.

License

Apache-2.0. See LICENSE.

Metadata

Release files for mlx-learn 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

Source distribution for mlx-learn 0.1.0a2
File Size Uploaded Provenance Actions
mlx_learn-0.1.0a2.tar.gz 93.9 kB With provenance Details for mlx_learn-0.1.0a2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mlx-learn 0.1.0a2
File Interpreter ABI Platform Actions
mlx_learn-0.1.0a2-py3-none-any.whl Python 3 none any Details for mlx_learn-0.1.0a2-py3-none-any.whl

Total release size: 203.5 kB

Release files / mlx_learn-0.1.0a2.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL mlx_learn-0.1.0a2.tar.gz
Size 93.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a6aaa6e4f435cc163af5af6dfeaaa1bbe4c68292e85b60dad1646109df85a512
BLAKE2b-256 checksum
How to use checksums
f3e16abee13985f7de90b08735acec7d128484e10445b4b44a9383c1a26d8bb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / mlx_learn-0.1.0a2-py3-none-any.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL mlx_learn-0.1.0a2-py3-none-any.whl
Size 109.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acfafeea5fb3e052d1ce2e0d95da3b3e0e9e00f33626219112cea6608f1e53dc
BLAKE2b-256 checksum
How to use checksums
e33ff456f46a0db2c2a619d849748736a7aa923332f5cf9bc5dec54a400a5680
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Security for mlx-learn 0.1.0a2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Change of provenance

The repository and configuration that created this release differ from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 2 files

Attestation for mlx_learn-0.1.0a2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page