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.2.tar.gz (10.0 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.2-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: skml_json-1.0.2.tar.gz
  • Upload date:
  • Size: 10.0 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.2.tar.gz
Algorithm Hash digest
SHA256 7202035dc42b6a61af0f90feed249ff764afa940d2ed004c6cf06dc0a14f23a0
MD5 d21220eed5e0c8479770ac8dacfead60
BLAKE2b-256 2ffa62a018a4e97c416e362482288f3b418f638943d430e0f71d00cbdea14887

See more details on using hashes here.

File details

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

File metadata

  • Download URL: skml_json-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 838e93e8a1a95c1e41417d80044be101fcfbb0664dcc997657eee9f25ac3767a
MD5 a12b1e7720cf2e0ad5a1a8dfd2605a0b
BLAKE2b-256 519426756c764361276cbfc053f3e1c2dec9750f2bfc0df0155a643cbbc9ecbd

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