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

Clip the range of histograms when there are outliers #1157

Merged
merged 8 commits into from
Nov 27, 2024

Conversation

jeromedockes
Copy link
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
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
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
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

@@ -115,6 +117,67 @@ def _adjust_fig_size(fig, ax, target_w, target_h):
fig.set_size_inches((w, h))


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
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
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
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
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
25 checks passed
@jeromedockes jeromedockes deleted the better-histograms branch November 27, 2024 14:08
@jeromedockes
Copy link
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