A box plot compresses a whole column into five numbers and a few dots, which is why it is the standard way to compare many distributions side by side. Every part of the picture is a statistic: the line in the box is the median, the box edges are the quartiles, the whiskers reach out to the most extreme values that are not suspiciously far away, and the dots beyond the whiskers are the points the rule flags as outliers. Computing those numbers is the job of the plotting library, and this question builds them so the picture can be read for what it says and checked against the data. It relates directly to 03-outlier-detection, whose IQR rule is the same rule that places the whiskers.
Implement five_number_summary(x), the minimum, first quartile, median, third quartile and maximum, then box_plot_stats(x, whisker), which returns everything a box plot draws: the quartiles, the whisker ends and the outliers beyond them. The signatures and docstrings are already in the editor.
x is a 1D float array with at least one value.five_number_summary returns a tuple (minimum, q1, median, q3, maximum) of floats. Quartiles use linear interpolation between order statistics, the default of np.percentile.box_plot_stats(x, whisker) returns a dict with keys "q1", "median", "q3", "lower_whisker", "upper_whisker" and "outliers". The fences are q1 - whisker * IQR and q3 + whisker * IQR where IQR = q3 - q1. The upper whisker is the largest value of x that is at most the upper fence, and the lower whisker is the smallest value that is at least the lower fence. "outliers" is a sorted 1D float array of the values outside the fences.whisker is a non-negative float, 1.5 by default. Inputs must not be modified. Do not call np.percentile more than needed, and do not use a plotting library.The whiskers end at actual data values, not at the fences themselves. The fence only decides which values count as too far out.
A value exactly on a fence is inside it, so only values strictly beyond the fences are outliers.
If there are no outliers on a side, that whisker reaches the minimum or maximum of the data.
No results yet
Run your code to check it against the examples, or submit to run every test.