0
$\begingroup$

Let's say I've found some outliers in a column in my dataset and have decided to remove them.

Should I do this before or after I split the dataset into train/test sets?

$\endgroup$
2
  • $\begingroup$ Why would you remove the outliers? $\endgroup$
    – Dave
    Jul 5, 2021 at 16:57
  • $\begingroup$ We want our models to model the general trend of something. Perhaps the outliers skew the trend in one way or another and make the models less performant? $\endgroup$
    – codeananda
    Jul 30, 2021 at 12:50

3 Answers 3

2
$\begingroup$

If you decided to remove outliers. Please remove them before the split(even not only before a split, it's better to do the entire analysis(stat-testing, visualization) again after removing them, you may find interesting things by doing this).

If you remove outliers in only any one of train/test set it will create more problems. (EX: An outlier in train set may not be an outlier in combined/full set, also the model will have high variance if you do so)

$\endgroup$
2
  • 1
    $\begingroup$ @vekatesh U are right absolutely. One should always wipe features in prior if it founds. $\endgroup$ Jun 9, 2020 at 6:55
  • 4
    $\begingroup$ I disagree with @venkatesh, actually in order to prevent any form of leakage the first thing you have to do is splitting between train and test. Test is something you should not be able to see until the very last moment, if you remove outliers before splitting you are contaminating the test. $\endgroup$
    – rusiano
    Jul 5, 2021 at 14:33
0
$\begingroup$

I think two case is not different too much. (Eventually the all outlier is deleted)

But the proportion of the train/test set(e.x : 7:3) may different if you remove the outlier after the split.

So I recommend remove outlier before split if you could.

$\endgroup$
0
$\begingroup$

I would agree with @rusiano. If you remove outliers before split, you are affecting test/validation data. Test data should be unspoiled.

Regarding @VenkateshGandi answer: "If you remove outliers in only any one of train/test set it will create more problems.". In this case, don't remove outliers. Removing outliers is not always useful.

$\endgroup$
2
  • $\begingroup$ Welcome @HD2000! Would you be able to provide a reference or source to look into for further reading on this? Thanks! $\endgroup$
    – hH1sG0n3
    Jun 30, 2022 at 10:45
  • 1
    $\begingroup$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Jun 30, 2022 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.