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

ValueError: Line in unexpected format #248

Open
sharthZ23 opened this issue Dec 4, 2017 · 0 comments · May be fixed by #249
Open

ValueError: Line in unexpected format #248

sharthZ23 opened this issue Dec 4, 2017 · 0 comments · May be fixed by #249

Comments

@sharthZ23
Copy link

sharthZ23 commented Dec 4, 2017

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.

sharthZ23 added a commit to sharthZ23/eli5 that referenced this issue Dec 7, 2017
@sharthZ23 sharthZ23 linked a pull request Dec 7, 2017 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants