Treating Outliers in Python

8 / 16

Winsorization Method or Percentile Capping

This method is similar to IQR method. If any value exceeds the value of the 99th percentile or is below the 1st percentile then they are treated as outliers.

  • First, we will import Numpy as np

    import numpy as <<your code goes here>>
  • Then, we will use the same datapoints we used ealier

    x = [5, 5, 5, -99, 5, 5, 5, 5, 5, 5, 88, 5, 5, 5]
  • Now, we will define a function winsorization_outliers to detect the outliers

    def <<your code goes here>>(data):
        q1 = np.percentile(data, 1)
        q3 = np.percentile(data, 99)
        for i in data:
            if i > q3 or i < q1:
  • Finally, we will call this function using our datapoints

    winsorization_outliers(<<your code goes here>>)
See Answer

No hints are availble for this assesment

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...