sklearn-export
This package is based on sklearn porter from https://github.com/nok/sklearn-porter. I choose to build it because sklearn porter saves data in matrix format. However, most popular algebra libraries (e.g., blas and lapack) are used to work with vectors. Then, sklearn-export saves the sklearn model data in Json format (matrices are stored in column major order). Note that, this is a beta version yet, then only some models and functionalities are supported.
New features (0.0.7)
The code was optimized and now it works with sklearn >= 0.24. Some complete examples were added (see Complete Examples section).
Support
| Class | Details |
|---|---|
| sklearn.svm.SVC | C-Support Vector Classification. The multiclass support is handled according to a one-vs-one scheme. |
| sklearn.svm.NuSVC | Nu-Support Vector Classification. Similar to SVC but uses a parameter to control the number of support vectors. |
| sklearn.svc.LinearSVC | Linear Support Vector Classification. |
| sklearn.neural_network.MLPClassifier | Multi-layer Perceptron classifier. |
| sklearn.neural_network.MLPRegressor | Multi-layer Perceptron regressor. |
| sklearn.linear_model.LogisticRegression | Logistic Regression (aka logit, MaxEnt) classifier. |
| sklearn.linear_model.LinearRegression | Ordinary least squares Linear Regression. |
| sklearn.preprocessing.MinMaxScaler | Transforms features by scaling each feature to a given range. |
| sklearn.preprocessing.StandardScaler | Standardize features by removing the mean and scaling to unit variance. |
| sklearn.svm.SVR | Epsilon-Support Vector Regression. |
| sklearn.svm.LinearSVR | Linear Support Vector Regression. |
Observation: details were extracted from sklearn documentation.
Installation
We recommend to make a instalation using pip:
$ pip install sklearn_export
If you are using jupyter notebooks consider to install sklearn_export through a notebook cell. Then, you can type and execute the following:
import sys
!{sys.executable} -m pip install sklearn_export
Usage
Actually sklearn-export can save Classifiers, Regressions and some Scalers (see Support session).
Saving a Model or Scaler
The basic usage is to save a simple model.
# Basic imports
from sklearn.datasets import load_iris
from sklearn_export import Export
from sklearn.neural_network import MLPRegressor
# Load data and train model
samples = load_iris()
X, y = samples.data, samples.target
clf = MLPRegressor()
clf.fit(X, y)
# Save using sklearn_export
export = Export(clf)
result = export.to_json()
The result is a Json file that can be loaded in any language.
Complete examples
Some complete examples are provided here.
Saving a Model and a Scaler
The sklearn-export can also save more then one class in the same Json. This is usefull to store a Classifier and a Scaler (for example). To be honest, actually is only possible to store a pair Model and Scaler.
# Basic imports
from sklearn.datasets import load_iris
from sklearn_export import Export
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPRegressor
# Load data
samples = load_iris()
X, y = samples.data, samples.target
# Normalize data
scaler = StandardScaler()
Xz = scaler.fit_transform(X)
# Train model with normalized data
clf = MLPRegressor()
clf.fit(Xz, y)
# Save model and scaler using sklearn_export
export = Export([scaler, clf])
result = export.to_json()
The result is a Json file that contains information about a Model and a Scaler. The file can be loaded in any programing language.
Extra options
The method to_json() also support some other parameters:
| Parameter | Details | Default |
|---|---|---|
filename |
Name of the output Json file | data.json |
directory |
Path to save the file | . |
with_md5_hash |
Include md5 hash in file name | False |
Questions
If you have any question please send me a mail charles26f@gmail.com.
Metadata
Release files for sklearn-export 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sklearn-export-0.0.7.tar.gz | 11.8 kB | Without provenance | Details for sklearn-export-0.0.7.tar.gz |
Release files / sklearn-export-0.0.7.tar.gz
| Download URL | sklearn-export-0.0.7.tar.gz |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62eb414f8ff6625ae0a22416e4e4372bb5631dd7fe8496bd86b9ce6f61a78bbe
|
|
BLAKE2b-256 checksum How to use checksums |
f069584fd038f0aee86f2f70a022420a6ab86385f6459f881306b81dbb74026c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Security for sklearn-export 0.0.7
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.