Skip to main content

Export scikit-learn models to JSON for cross-language inference

Project description

skjson

Export scikit-learn models to JSON for cross-language inference.

Installation

pip install skjson

Quick Start

Check out the demo notebook for an example training a Random Forest on the Iris dataset:

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
import skjson

# Load the Iris dataset and split
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a Random Forest classifier
clf = RandomForestClassifier(random_state=42)
clf.fit(X_train, y_train)

# Export the trained model to JSON
skjson.save(clf, 'demo.json')

# Load and reuse the model
predictor = skjson.load("demo.json")

Support models for conversion

Linear Models (sklearn.linear_model)

  • LinearRegression, Ridge, Lasso, ElasticNet
  • LogisticRegression

Tree-based Models (sklearn.tree, sklearn.ensemble)

  • DecisionTreeClassifier, DecisionTreeRegressor
  • RandomForestClassifier, RandomForestRegressor
  • GradientBoostingClassifier, GradientBoostingRegressor

Support Vector Machines (sklearn.svm)

  • SVC, SVR, LinearSVC

Neighbors (sklearn.neighbors)

  • KNeighborsClassifier, KNeighborsRegressor

Naive Bayes (sklearn.naive_bayes)

  • GaussianNB

Preprocessing (sklearn.preprocessing)

  • StandardScaler, MinMaxScaler, LabelEncoder

Future Directions

  • Support for scikit-learn Pipeline objects and feature unions.
  • npm package for inference using our json models
  • Support for sklearn.neural_network models

Note

  • This project built with Google Gemini and Claude Opus.
  • If you wish to contribute, please contact me.

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

skjson-0.1.1.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skjson-0.1.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file skjson-0.1.1.tar.gz.

File metadata

  • Download URL: skjson-0.1.1.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for skjson-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5e5133c65d6623e79a81ccf71624b00ecc9c58c56aa96e367f9e08c59ad51ae5
MD5 6da43146dcea1d45f5b479bf0105afab
BLAKE2b-256 fcd95fa48ce3eb3cfce78baef2d8d8145558b165af2f920be6c430cb3f1b536e

See more details on using hashes here.

Provenance

The following attestation bundles were made for skjson-0.1.1.tar.gz:

Publisher: publish.yml on hongyaok/skjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file skjson-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: skjson-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for skjson-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 304fc80dac0b6e9a362406450d0e63de0c41b49982db0aa0c2983ede186c8c52
MD5 9e18cfdfa534a6ae339d0d0ff725ebf5
BLAKE2b-256 57305e042443eda150ecf5121cfb3ca93169aac417831ab4316066471613d4c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for skjson-0.1.1-py3-none-any.whl:

Publisher: publish.yml on hongyaok/skjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page