Skip to content

visualize has a bug for categorical features  #119

@arrabi

Description

@arrabi

This is regarding this file:
https://github.com/interpretml/interpret/blame/master/python/interpret-core/interpret/data/response.py

MarginalExplanation.visualize(key) has a bug that prevents it from processing categorical features correctly. Changing the following lines will fix it:

move line #137:
bin_size = density_dict["names"][1] - density_dict["names"][0]

to be in the else (line #142)
if is_categorical:
trace1 = go.Histogram(x=data_dict["x"], name="x density", yaxis="y2")
else:
bin_size = density_dict["names"][1] - density_dict["names"][0]
trace1 = go.Histogram(
x=data_dict["x"],
name="x density",
yaxis="y2",
autobinx=False,
xbins=dict(
start=density_dict["names"][0],
end=density_dict["names"][-1],
size=bin_size,
),
)

and then move line 154:
resp_bin_size = density_dict["names"][1] - density_dict["names"][0]

create a new if statement, and put this line there: (line 157)
if is_categorical:
trace2 = go.Histogram(x=data_dict["y"], name="y density", xaxis="x2")
else:
resp_bin_size = density_dict["names"][1] - density_dict["names"][0]
trace2 = go.Histogram(
y=data_dict["y"],
name="y density",
xaxis="x2",
autobiny=False,
ybins=dict(
start=resp_density_dict["names"][0],
end=resp_density_dict["names"][-1],
size=resp_bin_size,
),
)

this would resolve the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions