0
$\begingroup$

Suppose I have a train and test data set and both of them contain missing values. Can I join both of them and then do fillna.(alldata.mean()) or will that cause data leakage. What would be a better way because doing them separately would have different mean for same column.

$\endgroup$

2 Answers 2

2
$\begingroup$

This is a controversial subject with no clear best answer and myriad options, some of which are model-specific. You can drop them, replace them with extreme values, interpolate, replace with median, impute with nearest neighbors, etc. In all cases besides dropping them altogether, you make assumptions and create data where no data exists. I can't tell you the best approach, but I can advise you to try multiple approaches and hope the end results are robust to choice.

$\endgroup$
1
$\begingroup$

No you shouldn't do that as the statistics of your training set and your test set isn't the same..

We apply the same transformations on both the data-sets but not using the same statistics..

Also why always filling by mean is preferred?

Search for interpolation in data-frames (requires scipy)

$\endgroup$

Your Answer

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

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