Skip to content

Instantly share code, notes, and snippets.

@jlopezpena
jlopezpena / skleanr2json.py
Created September 28, 2018 09:37
Barebones JSON serialization for simple (non-nested) sklearn models
from pandas.io import json
import numpy as np
def model_to_dict(model):
attrs = model.__dict__
init_attrs = {key: val for key, val in attrs.items() if not key.endswith("_")}
fitted_attrs = {key: val for key, val in attrs.items() if key.endswith("_")}
name = model.__class__.__name__
module = model.__module__