andosa / treeinterpreter

BSD 3-Clause "New" or "Revised" License
745 stars 140 forks source link

fix IndexError if tree value is squeezed into a single float #2

Closed janrygl closed 9 years ago

janrygl commented 9 years ago

For some trees in sklearn, the package raises error:

    return _predict_forest(model, X)
  File "python2.7/site-packages/treeinterpreter/treeinterpreter.py", line 96, in _predict_forest
    pred, bias, contribution = _predict_tree(tree, X)
  File "python2.7/site-packages/treeinterpreter/treeinterpreter.py", line 74, in _predict_tree
    biases[row] = values[path[0]]

Error happens when tree value is squeezed into float instead of the 1-D array of floats.

andosa commented 9 years ago

Thanks for the fix, merged