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

Add statistics attribute to slicefinder #40

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 35 additions & 1 deletion sliceline/slicefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ class Slicefinder(BaseEstimator, TransformerMixin):
average_error_: float
Mean value of the input error.

top_slices_statistics_: list of dict of length `len(top_slices_)`
The statistics of the slices found sorted by slice's scores.
For each slice, the following statistics are stored:
- slice_score: the score of the slice (defined in `_score` method)
- sum_slice_error: the sum of all the errors in the slice
- max_slice_error: the maximum of all errors in the slice
- slice_size: the number of elements in the slice
- slice_average_error: the average error in the slice (sum_slice_error / slice_size)

References
----------
`SliceLine: Fast, Linear-Algebra-based Slice Finding for ML Model Debugging
Expand All @@ -92,7 +101,8 @@ def __init__(
self.verbose = verbose

self._one_hot_encoder = self._top_slices_enc = None
self.top_slices_ = self.average_error_ = None
self.top_slices_ = self.top_slices_statistics_ = None
self.average_error_ = None

if self.verbose:
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -679,4 +689,28 @@ def _search_slices(
top_k_slices
)

# compute slices' average errors
top_k_statistics = np.column_stack(
(
top_k_statistics,
np.divide(top_k_statistics[:, 1], top_k_statistics[:, 3]),
)
)

# transform statistics to a list of dict
statistics_names = [
"slice_score",
"sum_slice_error",
"max_slice_error",
"slice_size",
"slice_average_error",
]
self.top_slices_statistics_ = [
{
stat_name: stat_value
for stat_value, stat_name in zip(statistic, statistics_names)
}
for statistic in top_k_statistics
]

logger.debug("Terminated at level %i." % level)
Loading