Python Seaborn - 如何在箱线图中确定异常值

Python Seaborn - How are outliers determined in boxplots

我想知道在 Seaborn 中使用什么算法来确定箱线图分布中的 'outliers'。

在他们的网站上 seaborn.boxplot 他们简单地说:

The box shows the quartiles of the dataset while the whiskers extend to show the rest of the distribution, except for points that are determined to be “outliers” using a method that is a function of the inter-quartile range.

我很想知道他们用的是什么方法。我从数据框创建了箱线图,我似乎有很多 'outliers'.

谢谢

如果您在链接的页面上进一步阅读(或 ctrl-f "outlier"),您将看到:

whis : float, optional
    Proportion of the IQR past the low and high quartiles to extend the plot whiskers.
    Points outside this range will be identified as outliers.

经测试,seaborn 似乎默认使用 whis=1.5

whis 定义为

Proportion of the IQR past the low and high quartiles to extend the plot whiskers.

对于正态分布,interquartile range 包含 50% 的总体,1.5 * IQR 包含大约 99%。

你可以这样计算:

Q1 = df.quartile(0.25)
Q3 = df.quartile(0.75)
    
IQR = Q3 - Q1

如果小于:

,则为离群值
Q1 - 1.5 * IQR

或者如果它大于:

Q3 + 1.5 * IQR