A scikit-learn compatible neural network library that wraps MLX.
Project description
SKLX
A scikit-learn compatible neural network library that wraps MLX. Highly inspired by skorch.
Examples
import numpy as np
from sklearn.datasets import make_classification
from mlx import nn
from sklx import NeuralNetClassifier
X, y = make_classification(1000, 20, n_informative=10, random_state=0)
X = X.astype(np.float32)
y = y.astype(np.int64)
class MyModule(nn.Module):
def __init__(self, num_units=10, nonlin=nn.ReLU()):
super().__init__()
self.dense0 = nn.Linear(20, num_units)
self.nonlin = nonlin
self.dropout = nn.Dropout(0.5)
self.dense1 = nn.Linear(num_units, num_units)
self.output = nn.Linear(num_units, 2)
self.softmax = nn.Softmax(dim=-1)
def forward(self, X, **kwargs):
X = self.nonlin(self.dense0(X))
X = self.dropout(X)
X = self.nonlin(self.dense1(X))
X = self.softmax(self.output(X))
return X
net = NeuralNetClassifier(
MyModule,
max_epochs=10,
lr=0.1,
)
net.fit(X, y)
y_proba = net.predict_proba(X)
In an sklearn Pipeline:
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
pipe = Pipeline([
('scale', StandardScaler()),
('net', net),
])
pipe.fit(X, y)
y_proba = pipe.predict_proba(X)
With grid search:
from sklearn.model_selection import GridSearchCV
params = {
'lr': [0.01, 0.02],
'max_epochs': [10, 20],
'module__num_units': [10, 20],
}
gs = GridSearchCV(net, params, refit=False, cv=3, scoring='accuracy', verbose=2)
gs.fit(X, y)
print("best score: {:.3f}, best params: {}".format(gs.best_score_, gs.best_params_))
Future Roadmap
- Completing Feature Parity with Skorch
Pipeline SupportGrid Search Support- Learning Rate Scheduler https://github.com/lazarust/sklx/issues/6
- Scoring https://github.com/lazarust/sklx/issues/7
- Early Stopping https://github.com/lazarust/sklx/issues/8
- Checkpointing https://github.com/lazarust/sklx/issues/9
- Parameter Freezing https://github.com/lazarust/sklx/issues/10
- Progress Bar https://github.com/lazarust/sklx/issues/11
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sklx-0.0.9.tar.gz.
File metadata
- Download URL: sklx-0.0.9.tar.gz
- Upload date:
- Size: 233.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89773ac98259c00e0781ad31fd6642be87569112b57454cd5271fb1106f4234b
|
|
| MD5 |
2ae71a564fc74365a5548eefc74b3267
|
|
| BLAKE2b-256 |
ed66dce9d8948a43fe490a454ff0a62fd4900b2c311b760bcea755b07ae94abc
|
Provenance
The following attestation bundles were made for sklx-0.0.9.tar.gz:
Publisher:
python-publish.yml on lazarust/sklx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sklx-0.0.9.tar.gz -
Subject digest:
89773ac98259c00e0781ad31fd6642be87569112b57454cd5271fb1106f4234b - Sigstore transparency entry: 829620480
- Sigstore integration time:
-
Permalink:
lazarust/sklx@29796f40d97fc59e8c326b1f197aaa982685e25e -
Branch / Tag:
refs/tags/v0.0.9 - Owner: https://github.com/lazarust
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@29796f40d97fc59e8c326b1f197aaa982685e25e -
Trigger Event:
release
-
Statement type:
File details
Details for the file sklx-0.0.9-py3-none-any.whl.
File metadata
- Download URL: sklx-0.0.9-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e8f1b1ba2f76a69d5e86c055c94998d17d1dfdb125defc2fd29ce09bc7a023b
|
|
| MD5 |
a57aae1b6b512d94bc2d4b80edc9c6d4
|
|
| BLAKE2b-256 |
5548745fe26f7c709c530cc5a47a38ad2b1bf1f945f9b6cde0aa2bb6279133e1
|
Provenance
The following attestation bundles were made for sklx-0.0.9-py3-none-any.whl:
Publisher:
python-publish.yml on lazarust/sklx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sklx-0.0.9-py3-none-any.whl -
Subject digest:
3e8f1b1ba2f76a69d5e86c055c94998d17d1dfdb125defc2fd29ce09bc7a023b - Sigstore transparency entry: 829620494
- Sigstore integration time:
-
Permalink:
lazarust/sklx@29796f40d97fc59e8c326b1f197aaa982685e25e -
Branch / Tag:
refs/tags/v0.0.9 - Owner: https://github.com/lazarust
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@29796f40d97fc59e8c326b1f197aaa982685e25e -
Trigger Event:
release
-
Statement type: