Skip to content

Clip the range of histograms when there are outliers#1157

Merged
jeromedockes merged 8 commits into
skrub-data:mainfrom
jeromedockes:better-histograms
Nov 27, 2024
Merged

Clip the range of histograms when there are outliers#1157
jeromedockes merged 8 commits into
skrub-data:mainfrom
jeromedockes:better-histograms

Conversation

@jeromedockes
Copy link
Copy Markdown
Member

fixes #1155

this limits the range of data shown in some histograms to avoid having all the data in one bin and seeing no details of the distribution

@jeromedockes
Copy link
Copy Markdown
Member Author

jeromedockes commented Nov 25, 2024

skrub 0.3.1:

screenshot_2024-11-25T15:22:31+01:00

this pr:

screenshot_2024-11-25T15:22:41+01:00

@jeromedockes
Copy link
Copy Markdown
Member Author

I'm sure the heuristic used to choose the range can be improved so if anybody gets the chance to try it on a couple of datasets and see how it looks that would be very helpful

to avoid clipping very close to the actual min or max
@jeromedockes jeromedockes marked this pull request as ready for review November 25, 2024 16:21
@jeromedockes jeromedockes added this to the 0.3.2 milestone Nov 26, 2024
Copy link
Copy Markdown
Member

@Vincent-Maladiere Vincent-Maladiere left a comment

Choose a reason for hiding this comment

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

Works fine when there are left and right outliers (yes, prices can be negative)

Screenshot 2024-11-27 at 14 39 33

without this PR:

Screenshot 2024-11-27 at 14 49 59

Comment thread skrub/_reporting/_plotting.py Outdated

def _get_range(values, frac=0.2, factor=3.0):
min_value, low_p, high_p, max_value = np.percentile(
values, [0, frac * 100.0, (1.0 - frac) * 100.0, 100.0]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

np.quantile to simplify this line?

delta = high_p - low_p
if not delta:
return min_value, max_value
margin = factor * delta
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting heuristic, how did you get these default parameters?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

from the random number generator in my head 😅 as mentioned I think the heuristic can definitely be refined or replaced with somehting else

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought of using the inter-quantile range because that's what box plots do, but I think we could read more about simple outlier detection methods

@jeromedockes jeromedockes merged commit a7abe4b into skrub-data:main Nov 27, 2024
@jeromedockes jeromedockes deleted the better-histograms branch November 27, 2024 14:08
@jeromedockes
Copy link
Copy Markdown
Member Author

thanks for the review @Vincent-Maladiere :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clip range of histograms in TableReport

2 participants