SkLearn IQR function

### Describe the workflow you want to enable

Recently, I was working on a machine learning project with a dataset that was quite skewed. I repeatedly had to compute the interquartile range (IQR), calculate the 25th and 75th percentiles, visualize the box plot, and then remove outliers — all manually.

While this wasn't an issue at first, it became tedious to write the same code over and over again for different rows and columns. This made me wonder: Wouldn’t it be much more efficient if scikit-learn offered a built-in utility to calculate the IQR and optionally remove or flag outliers?

I believe this kind of functionality could significantly streamline the preprocessing workflow for many users.

### Describe your proposed solution

I’d like to suggest adding a simple utility class to scikit-learn (or as part of a preprocessing module), called OutlierRemoval. This class would encapsulate all IQR-related preprocessing logic and expose a clean interface for users to apply it.

```py
class OutlierRemoval:
    def __init__(self, multiplier: float = 1.5):
        # Multiplier for the IQR rule (default is 1.5)
        ...

    def get_q1(self, X, column):
        # Returns the 25th percentile for a column
        ...

    def get_q3(self, X, column):
        # Returns the 75th percentile for a column
        ...

    def calculate_iqr(self, X, column):
        # Returns IQR = Q3 - Q1
        ...

    def plot_boxplot(self, X, column):
        # Displays a boxplot for the column
        ...

    def remove_outliers(self, X, column):
        # Removes rows with outliers from the dataset
        ...
```

Prevents redundant code when handling outliers across multiple projects

Encourages best practices in preprocessing pipelines

Makes exploratory data analysis (EDA) cleaner and more intuitive

Aligns with scikit-learn’s emphasis on reusable, composable preprocessing tools

### Describe alternatives you've considered, if relevant

I've used pandas and numpy to manually calculate percentiles and remove outliers column by column. While effective, it becomes repetitive and error-prone in large or automated workflows. A reusable, built-in utility in scikit-learn would improve consistency and save time.

### Additional context

I’d be happy to contribute a first version of this feature and refine it based on maintainer feedback. I’m currently exploring scikit-learn as a first open-source contribution and this idea came directly from real-world project pain points.

COMMENT:
Thanks for opening an issue!

It is great to hear that you are motivated to contribute to scikit-learn 🙏. I would suggest to start with something easier than adding a new feature. Feel free to have a look at our [contributing guide](https://scikit-learn.org/dev/developers/contributing.html).

You may want to have a look at https://github.com/scikit-learn/scikit-learn/issues/26706 and also https://github.com/scikit-learn/scikit-learn/issues/9630 for some more context. At the moment, scikit-learn transformers can not change the number of samples. There has been discussion to change this but it's fair to say that it's unlikely to converge in the near future.

I guess your best bet right now I would say is to look at this [example](https://imbalanced-learn.org/dev/auto_examples/applications/plot_outlier_rejections.html#sphx-glr-auto-examples-applications-plot-outlier-rejections-py) from the imbalanced-learn documentation.

Labels: New Feature