Enrollments started for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 5 Seats Left
Apply NowLogin using Social Account
     Continue with GoogleLogin using your credentials
In this method we will use the Inter Quartile Range(IQR) to detect outliers. IQR tells us the variation in the data set. Any value, which is beyond the range of -1.5 x IQR to 1.5 x IQR are treated as outliers
First, we will import Numpy
as np
import numpy as <<your code goes here>>
Next, we will define the datapoints we had used previously
x = [5, 5, 5, -99, 5, 5, 5, 5, 5, 5, 88, 5, 5, 5]
Now, we will define a function calculate_iqr
to detect the outliers using the IQR method
def <<your code goes here>>(data):
Q1 = np.percentile(data, 25, interpolation = 'midpoint')
Q2 = np.percentile(data, 50, interpolation = 'midpoint')
Q3 = np.percentile(data, 75, interpolation = 'midpoint')
IQR = Q3 - Q1
low_lim = Q1 - 1.5 * IQR
up_lim = Q3 + 1.5 * IQR
outlier =[]
for num in x:
if ((num> up_lim) or (num<low_lim)):
outlier.append(num)
print("Outliers:",outlier)
Finally, we will call the function using our datapoints
<<your code goes here>>(x)
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...