# NaN error on KernelKNN regression

anyone can help me please? there's an error when i'm trying to make output with testing data 10% and 1000 times simulation.

``````#pemanggilan paket yang digunakan
library(caret)
library(KernelKnn)

#perhitungan akurasi prediksi dengan 100 kali simulasi
sim = function(B, p1, k1)
{
hasileu = matrix(0, B, 4)
for (i in 1:B)
{
#memanggil data boston
boston = MASS::Boston

#membagi data train dan data test
indexes = createDataPartition(boston\$medv, p = p1, list = F)
train = boston[indexes, ]
test = boston[-indexes, ]

train_x = train[, -14]
train_x = scale(train_x)[,]
train_y = train[,14]

test_x = test[, -14]
test_x = scale(test[,-14])[,]
test_y = test[,14]

#model prediksi regresi KNN
pred1 = KernelKnn(train_x, TEST_data = test_x, train_y, k = k1, method = 'euclidean', weights_function = NULL, regression = T)

#perhitungan akurasi
mse = mean((test_y - pred1)^2)
mae = mean(abs(test_y - pred1))
rmse = sqrt(mse)
mape = mean(abs((test_y - pred1)/test_y))
r2 = cor(test_y, pred1)^2
hasileu[i,1] = rmse
hasileu[i,2] = mape
hasileu[i,3] = mae
hasileu[i,4] = r2
}
return(apply(hasileu, 2, mean))
}

#penentuan rentang nilai K
hitung.variasi.k = function(B,p,K)
{
has11 = matrix(0,K,4)
for (i in 1:K)
{
has11[i,] = sim(B,p,i)
}
has11
}

#hasil akurasi berbagai proporsi data uji
K = 10
has11 = hitung.variasi.k(1000, 0.9,K)
Error in KernelKnn(train_x, TEST_data = test_x, train_y, k = k1, method = "minkowski", :
the TEST_data includes missing values
``````

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.