Skip to main content

Export scikit-learn>=1.4.0 model files to JSON for sharing or deploying predictive models with peace of mind. Original by Mathieu Rodrigue

Project description

skml-json

Export scikit-learn model files to JSON for sharing or deploying predictive models with peace of mind.

Why skml-json?

Other methods for exporting scikit-learn models require Pickle or Joblib (based on Pickle). Serializing model files with Pickle provides a simple attack vector for malicious users-- they give an attacker the ability to execute arbitrary code wherever the file is deserialized. For an example see: https://www.smartfile.com/blog/python-pickle-security-problems-and-solutions/.

skml-json is a safe and transparent solution for exporting scikit-learn model files.

Safe

Export model files to 100% JSON which cannot execute code on deserialization.

Transparent

Model files are serialized in JSON (i.e., not binary), so you have the ability to see exactly what's inside.

Getting Started

makes exporting model files to JSON simple.

Install

pip install skml-json

Example Usage

import skml_json as skmljson
from sklearn.ensemble import RandomForestClassifier

model = RandomForestClassifier(n_estimators=10, max_depth=5, random_state=0).fit(X, y)

skmljson.to_json(model, file_name)
deserialized_model = skmljson.from_json(file_name)

deserialized_model.predict(X)

Features

skml-json requires scikit-learn >= 1.4.0.

Supported scikit-learn Models

  • Classification

    • sklearn.linear_model.LogisticRegression
    • sklearn.linear_model.Perceptron
    • sklearn.discriminant_analysis.LinearDiscriminantAnalysis
    • sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis
    • sklearn.svm.SVC
    • sklearn.naive_bayes.GaussianNB
    • sklearn.naive_bayes.MultinomialNB
    • sklearn.naive_bayes.ComplementNB
    • sklearn.naive_bayes.BernoulliNB
    • sklearn.tree.DecisionTreeClassifier
    • sklearn.ensemble.RandomForestClassifier
    • sklearn.ensemble.GradientBoostingClassifier
    • sklearn.neural_network.MLPClassifier
  • Regression

    • sklearn.linear_model.LinearRegression
    • sklearn.linear_model.Ridge
    • sklearn.linear_model.Lasso
    • sklearn.svm.SVR
    • sklearn.tree.DecisionTreeRegressor
    • sklearn.ensemble.RandomForestRegressor
    • sklearn.ensemble.GradientBoostingRegressor
    • sklearn.neural_network.MLPRegressor

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

skml_json-1.0.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

skml_json-1.0.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file skml_json-1.0.1.tar.gz.

File metadata

  • Download URL: skml_json-1.0.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for skml_json-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6d9d57fc29812437bd9deddb32bf84fc9e6b16f799e5988b2753f11229441331
MD5 b97e5321b65364f61548c3f93d2d0611
BLAKE2b-256 c6d4945e3d2c7dfbdd2d388f0723ba7338856108e226147cadf838e31f3d732b

See more details on using hashes here.

File details

Details for the file skml_json-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: skml_json-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for skml_json-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce050205c5a6d03f42f0a18c02694d039b6f4e7eac4e64d250a0b0309e746466
MD5 13d87a3957293bceea8ec2a3f1ce99a3
BLAKE2b-256 ba5f62bb93095bad691541ac30bd31f6f814bafa2a10ded0a3f2c4f7d0d7fc3c

See more details on using hashes here.

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