2
$\begingroup$

I have a dataset with 12 predictor variables and a binary response variable. There's 5960 observations. One of the predictor variables has 1,260 missing values so I'm using k-nearest neighbours to impute them. The distance metric is Euclidean and k = 1 is the default of the algorithm.

Question: Should I include the response variable in the k-nearest neighbours algorithm?

My thoughts were that this may introduce some sort of overfitting.

$\endgroup$
1
$\begingroup$

No, you shouldn't use the response variable. If the neighbours of a sample end up being other samples that are close in target variable, you'll fill in your features by looking at those samples and your overall success will be more optimistic.

Take KNNImputer from sklearn, it takes the target variable as input (for conforming with the fit/transform pattern), but never uses it.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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