Use KNN imputation
In the previous exercise, you used median imputation to fill in missing values in the breast cancer dataset, but that is not the only possible method for dealing with missing data.
An alternative to median imputation is k-nearest neighbors, or KNN, imputation. This is a more advanced form of imputation where missing values are replaced with values from other rows that are similar to the current row. While this is a lot more complicated to implement in practice than simple median imputation, it is very easy to explore in caret using the preProcess argument to train(). You can simply use preProcess = "knnImpute" to change the method of imputation used prior to model fitting.
本练习是课程的一部分
Machine Learning with caret in R
练习说明
breast_cancer_x and breast_cancer_y are loaded in your workspace.
- Use the
train()function to fit aglmmodel calledknn_modelto the breast cancer dataset. - Use KNN imputation to handle missing values.
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Apply KNN imputation: knn_model
knn_model <- train(
x = ___,
y = ___,
method = ___,
trControl = myControl,
preProcess = ___
)
# Print knn_model to console