Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightGBM multiclass convert error #153

Closed
little-eyes opened this issue Oct 18, 2018 · 1 comment
Closed

LightGBM multiclass convert error #153

little-eyes opened this issue Oct 18, 2018 · 1 comment

Comments

@little-eyes
Copy link

I try to add a test for lightgbm, but i found multiclass classification seems to have error:

=================================== FAILURES ===================================
_______ TestLGBMClassifierConverter.test_model_multiclass_classification _______

self = <test_LightGBMClassifier.TestLGBMClassifierConverter testMethod=test_model_multiclass_classification>

    def test_model_multiclass_classification(self):
        model = self._fit_model_binary_classification(LGBMClassifier(
            objective="ova",
            learning_rate=0.05,
            boosting_type="gbdt",
            num_class=10))
>       model_onnx = convert_sklearn(model, 'scikit-learn LGBM multiclass classifier', [('input', FloatTensorType([1, 10]))])

tests/sklearn/test_LightGBMClassifier.py:47: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
onnxmltools/convert/main.py:18: in convert_sklearn
    doc_string, targeted_onnx, custom_conversion_functions, custom_shape_calculators)
onnxmltools/convert/sklearn/convert.py:97: in convert
    onnx_model = convert_topology(topology, name, doc_string, targeted_onnx)
onnxmltools/convert/common/_topology.py:704: in convert_topology
    _registration.get_converter(operator.type)(scope, operator, container)
onnxmltools/convert/sklearn/operator_converters/LightGbm.py:140: in convert_lightgbm
    _parse_tree_structure(tree_id, class_id, learning_rate, tree['tree_structure'], attrs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tree_id = 2, class_id = 2, learning_rate = 1
tree_structure = {'leaf_value': -34.53877639770508}
attrs = {'class_ids': [0, 0, 0, 1, 1, 1], 'class_nodeids': [3, 4, 2, 3, 4, 2], 'class_treeids': [0, 0, 0, 1, 1, 1], 'class_weights': [0.004500000000000001, 0.005, -0.005000000000000001, -0.004500000000000001, -0.005, 0.005000000000000001], ...}

    def _parse_tree_structure(tree_id, class_id, learning_rate, tree_structure, attrs):
        # The pool of all nodes' indexes created when parsing a single tree. Different trees may use different pools.
        node_id_pool = set()
    
        node_id = _create_node_id(node_id_pool)
        left_id = _create_node_id(node_id_pool)
        right_id = _create_node_id(node_id_pool)
    
        attrs['nodes_treeids'].append(tree_id)
        attrs['nodes_nodeids'].append(node_id)
    
>       attrs['nodes_featureids'].append(tree_structure['split_feature'])
E       KeyError: 'split_feature'

onnxmltools/convert/sklearn/operator_converters/LightGbm.py:49: KeyError

The relevant code is here #152

@little-eyes
Copy link
Author

Actually, given the dataset is small but I produced too many trees which cause the problem. I reduced it, then it works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant