Outlier Detection and Removal Using IQR Method

Data Preparation & Feature Engineering DS practice problem on Onlearn.

Difficulty: medium.

Topics: Outlier Detection and Removal Using IQR Method, Interquartile Range (IQR), Tukey's Fences, Box-and-Whisker Plotting, Quantile Estimation, Winsorization, Data Preprocessing, Exploratory Data Analysis, Statistical Inference, Feature Engineering, Data Quality Assurance, Univariate Outlier Detection, Distribution Analysis, Data Cleaning Pipelines, Robust Statistics, Feature Scaling and Transformation.

Implement a function that detects and removes outliers from a dataset using the Interquartile Range (IQR) method. The IQR method identifies outliers as values that fall below Q1 k IQR or above Q3 + k IQR, where Q1 is the 25th percentile, Q3 is the 75th percentile, IQR = Q3 Q1, and k is a multiplier (commonly 1.5 for outliers or 3.0 for extreme outliers). Your function should take a list of numerical data and a multiplier k, then return a dictionary containing: 'cleaned data': the data with outliers removed (rounded to 4 decimal places) 'outlier indices': list of indices of detected outliers in the original data 'lower bound': the lower threshold for outlier detection (rounded to 4 decimal places) 'upper bound': the upper threshold for outlier detection (rounded to 4 decimal places)