I did the knn imputation following this post:
KNN imputation R packages
I met the error: Not sufficient complete cases for computing neighbors. Even when k = 1, this error occurs.
data.imputed <- knnImputation(data, k=3) Error in knnImputation(data) : Not sufficient complete cases for computing neighbors.
However the data should have sufficient complete cases. What's the problem?
dim(data) [1] 779 1558 sum(complete.cases(data)) [1] 600
Best Answer
I feel like this question would better belong on StackOverflow but I'll give it a go anyway:
paraphrasing the code for knnImputation (https://gist.github.com/tengpeng/fb6809717361319d8bde), you get that error message under the following conditions:
xcomplete <- data[setdiff(1:nrow(data),which(!complete.cases(data))),] if (nrow(xcomplete) < k) stop("Not sufficient complete cases for computing neighbors.")
I suggest you check the value of nrow(xcomplete) is equal to 600.
EDIT: As described in PR#16648, complete.cases can lead to spurious errors when some columns have classes with length or is.na methods, for example "POSIXlt".
Similar Posts:
- Solved – Error in knnImputation in r: Not sufficient complete cases for computing neighbors
- Solved – Error in knnImputation in r: Not sufficient complete cases for computing neighbors
- Solved – could not find function “xgb.DMatrix”
- Solved – Are complete statistics always sufficient
- Solved – Are complete statistics always sufficient