Get startedGet started for free

Calculating outlier limits with IQR

Visualizing outliers is usually only the first step in detecting outliers. To go beyond visualizing outliers, you will need to write code that isolates the outliers from the distribution.

In this exercise, you will implement the first step of what's going on under the hood of the boxplot. In other words, you will calculate the lower and upper outlier limits manually.

The distribution is available as prices.

This exercise is part of the course

Anomaly Detection in Python

View Course

Exercise instructions

  • Calculate the first and third quartiles of prices and store these as q1 and q3, respectively.
  • Calculate the IQR score into IQR.
  • Calculate the lower outlier limit into lower_limit.
  • Calculate the upper outlier limit into upper_limit.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate the 25th and 75th percentiles
q1 = prices.____(____)
q3 = prices.____(____)

# Find the IQR
IQR = ____
factor = 2.5

# Calculate the lower limit
lower_limit = ____ - ____

# Calculate the upper limit
upper_limit = ____ + ____
Edit and Run Code