def serializeRegressor(tree):
    """ Convert a sklearn.tree.DecisionTreeRegressor into a JSON-compatible format """
    LEAF_ATTRIBUTES = ['children_left', 'children_right', 'threshold', 'value',
                       'feature', 'impurity', 'weighted_n_node_samples']
    TREE_ATTRIBUTES = ['n_classes_', 'n_features_', 'n_outputs_']
    encoded = {
        'nodes': {},
        'tree': {},
        'n_leaves': len(tree.tree_.threshold),
        'params': tree.get_params()
    }
    for attr in LEAF_ATTRIBUTES:
        encoded['nodes'][attr] = getattr(tree.tree_, attr).tolist()
    for attr in TREE_ATTRIBUTES:
        encoded['tree'][attr] = getattr(tree, attr)
    return encoded