Created
June 13, 2017 03:16
-
-
Save nguyentienlong/6c203c4d937094d4d6edcab3c06e67e2 to your computer and use it in GitHub Desktop.
create python object with parameters from json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from sklearn.tree import * | |
import json | |
def object_decoder(obj): | |
klass = globals()[obj['__type__']] | |
objekt = klass() | |
for key in obj: | |
if key != '__type__': | |
setattr(objekt, key, obj[key]) | |
return objekt | |
jsonText = '{"__type__": "DecisionTreeClassifier","min_impurity_split": 4.984242514902916e-8,"min_samples_leaf": 9, "max_features": "auto", "min_weight_fraction_leaf": 0.002740675560709782,"min_samples_split": 8,"max_depth": 73,"class_weight": "alanced","random_state": 30,"presort": true}' | |
model = json.loads(jsonText, object_hook=object_decoder) | |
print(model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment