Skip to content

ValueError: Line in unexpected format #248

@sharthZ23

Description

@sharthZ23

Hi,

This code raise exception

from eli5 import show_prediction
show_prediction(gbtree.get_booster(), df[ds_cols].iloc[0])

Traceback

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-84-8f8dbfe0c6ec> in <module>()
----> 1 show_prediction(gbtree.get_booster(), df[ds_cols].iloc[0])

/usr/local/lib/python3.6/site-packages/eli5/ipython.py in show_prediction(estimator, doc, **kwargs)
    268     """
    269     format_kwargs, explain_kwargs = _split_kwargs(kwargs)
--> 270     expl = explain_prediction(estimator, doc, **explain_kwargs)
    271     html = format_as_html(expl, **format_kwargs)
    272     return HTML(html)

/usr/local/lib/python3.6/site-packages/singledispatch.py in wrapper(*args, **kw)
    208 
    209     def wrapper(*args, **kw):
--> 210         return dispatch(args[0].__class__)(*args, **kw)
    211 
    212     registry[object] = func

/usr/local/lib/python3.6/site-packages/eli5/xgboost.py in explain_prediction_xgboost(xgb, doc, vec, top, top_targets, target_names, targets, feature_names, feature_re, feature_filter, vectorized, is_regression, missing)
    194 
    195     scores_weights = _prediction_feature_weights(
--> 196         booster, dmatrix, n_targets, feature_names, xgb_feature_names)
    197 
    198     x = get_X0(add_intercept(X))

/usr/local/lib/python3.6/site-packages/eli5/xgboost.py in _prediction_feature_weights(booster, dmatrix, n_targets, feature_names, xgb_feature_names)
    258             ) for target_idx in range(n_targets)]
    259     else:
--> 260         scores_weights = [target_feature_weights(leaf_ids, tree_dumps)]
    261     return scores_weights
    262 

/usr/local/lib/python3.6/site-packages/eli5/xgboost.py in _target_feature_weights(leaf_ids, tree_dumps, feature_names, xgb_feature_names)
    271     score = 0
    272     for text_dump, leaf_id in zip(tree_dumps, leaf_ids):
--> 273         leaf = _indexed_leafs(_parse_tree_dump(text_dump))[leaf_id]
    274         score += leaf['leaf']
    275         path = [leaf]

/usr/local/lib/python3.6/site-packages/eli5/xgboost.py in _parse_tree_dump(text_dump)
    339     for line in text_dump.split('\n'):
    340         if line:
--> 341             depth, node = _parse_dump_line(line)
    342             if depth == 0:
    343                 assert not stack

/usr/local/lib/python3.6/site-packages/eli5/xgboost.py in _parse_dump_line(line)
    384             'cover': float(cover),
    385         }
--> 386     raise ValueError('Line in unexpected format: {}'.format(line))
    387 
    388 

ValueError: Line in unexpected format: 0:[path_type_/items/black_rook] yes=2,no=1,gain=0.443101,cover=371490

I think problem is in ->

'^(\t*)(\d+):\[([^<]+)<([^\]]+)\] '

My DataFrame have boolean values only, so there is no symbol < in nodes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions