Я новичок в области обработки данных, использующий R, и не могу устранить эту ошибку, а набор данных - это набор данных по раку простаты. Ошибка в prc_test_pred , которая говорит об ошибке в knn (train = prc_train, test = prc_test, cl = prc_train_labels,: никакие пропущенные значения не допускаются.
stringsAsFactors = FALSE
str(prc)
prc <- prc[-1] #removes the first variable(id) from the data set.
table(prc$diagnosis_result) # it helps us to get the numbers of patients
prc$diagnosis <- factor(prc$diagnosis_result, levels = c("B", "M"), labels = c("Benign", "Malignant")) #rename
round(prop.table(table(prc$diagnosis)) * 100, digits = 1) # it gives the result in the percentage form rounded of to 1 decimal place( and so it’s digits = 1)
normalize <- function(x) {
return ((x - min(x)) / (max(x) - min(x))) } #very important step (normalizes to a common scale)
prc_n <- as.data.frame(lapply(prc[2:9], normalize))
summary(prc_n$radius)
prc_train <- prc_n[1:65,]
prc_test <- prc_n[66:100,]
prc_train_labels <- prc[1:65, 1]
prc_test_labels <- prc[66:100, 1]
library(class)
prc_test_pred <- knn(train = prc_train, test = prc_test, cl = prc_train_labels,k=10)
library(gmodels)
CrossTable(x=prc_test_labels, y=prc_test_pred, prop.chisq=FALSE) ```