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

PR to handle columns of a dataframe that are not of type float #218

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
301eac9
when a row of a df is passed to an explainer tabular instance, error …
Jul 24, 2018
3d4f73f
handle case when a row is numpy.ndarray
RanaivosonHerimanitra Jul 25, 2018
9c7a461
fix error when retrieving names in np.ndarray
RanaivosonHerimanitra Jul 25, 2018
1e5b067
valueError to AttributeError for catching errors
RanaivosonHerimanitra Jul 25, 2018
ee29e5d
handle nonetype
RanaivosonHerimanitra Jul 26, 2018
6d694b5
handle nonetype corrected
RanaivosonHerimanitra Jul 26, 2018
c2e5c93
fill flake8 spec
RanaivosonHerimanitra Jul 26, 2018
f00f1c2
flake8 fix v2
RanaivosonHerimanitra Jul 26, 2018
86b105b
Delete init.py
RanaivosonHerimanitra Aug 7, 2018
bf6f8c5
delete table_perf.py
RanaivosonHerimanitra Aug 7, 2018
ba58035
delete text_perf.py
RanaivosonHerimanitra Aug 7, 2018
8b4affc
delete bundle.js
RanaivosonHerimanitra Aug 7, 2018
5f2f39f
delete __init__.py
RanaivosonHerimanitra Aug 7, 2018
0ffa5fb
delete webpack.config.js
RanaivosonHerimanitra Aug 7, 2018
f9faf16
delete lime_image.py
RanaivosonHerimanitra Aug 7, 2018
710dcc6
delete discretize.py
RanaivosonHerimanitra Aug 7, 2018
29569b4
delete explanation.py
RanaivosonHerimanitra Aug 7, 2018
ae5a834
delete exceptions.py
RanaivosonHerimanitra Aug 7, 2018
d4e686e
delete lime_base.py
RanaivosonHerimanitra Aug 7, 2018
1662e67
delete lime_tabular.py
RanaivosonHerimanitra Aug 7, 2018
82411c8
delete lime_text.py
RanaivosonHerimanitra Aug 7, 2018
0b2263f
delete test_discretize.py
RanaivosonHerimanitra Aug 7, 2018
eb80d02
delete test_generic
RanaivosonHerimanitra Aug 7, 2018
7865099
delete limte_text.py
RanaivosonHerimanitra Aug 7, 2018
7a5aafb
delete test_scikit_image
RanaivosonHerimanitra Aug 7, 2018
a9a4f9e
delete generic_utils.py
RanaivosonHerimanitra Aug 7, 2018
313b5d5
delete scikit_image.py
RanaivosonHerimanitra Aug 7, 2018
6819aae
delete test_lime_tabular
RanaivosonHerimanitra Aug 7, 2018
ebdb836
delete folder __init__
RanaivosonHerimanitra Aug 7, 2018
a84b631
delete folder utils init
RanaivosonHerimanitra Aug 7, 2018
af92188
delete folder wrappers init
RanaivosonHerimanitra Aug 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lime/lime_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,19 @@ def explain_instance(self,
feature_names = copy.deepcopy(self.feature_names)
if feature_names is None:
feature_names = [str(x) for x in range(data_row.shape[0])]

values = self.convert_and_round(data_row)

# get column names if numpy.ndarray or pandas df:
try:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we possibly check if the type is a pandas df rather than doing that via try / catch? It's a little awkward to have the most common use case be in an exception.

col_names = list(data_row.columns)
except AttributeError:
if data_row.dtype.names is not None:
col_names = list(data_row.dtype.names)
else:
col_names = []
if len(col_names) != 0:
if np.sum([1 if str(k).isdigit() else 0 for k in col_names]) != len(col_names):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this line. Why is it meaningful if column names are all digits, and why does it matter if all columns have digit names? Also, what happens if this is False? values seem to be undefined then

values = self.convert_and_round(data_row.values[0])
else:
values = self.convert_and_round(data_row)
for i in self.categorical_features:
if self.discretizer is not None and i in self.discretizer.lambdas:
continue
Expand Down