knn에 어떤 패키지를 사용하고 있습니까? 다음 (홍채 데이터 세트와 예)처럼 CV에 대한 caret를 사용할 수 있습니다
training <- iris
ctrl <- trainControl(method="repeatedcv",repeats = 3)
knnFit <- train(Species ~ ., data = training, method = "knn",
trControl = ctrl, preProcess = c("center","scale"))
knnFit
를 출력
k-Nearest Neighbors
150 samples
4 predictor
3 classes: 'setosa', 'versicolor', 'virginica'
Pre-processing: centered (4), scaled (4)
Resampling: Cross-Validated (10 fold, repeated 3 times)
Summary of sample sizes: 135, 135, 135, 135, 135, 135, ...
Resampling results across tuning parameters:
k Accuracy Kappa
5 0.9511111 0.9266667
7 0.9577778 0.9366667
9 0.9533333 0.9300000
Accuracy was used to select the optimal model using the largest value.
The final value used for the model was k = 7.
내가 KNN은 "클래스"패키지를 사용하고와. 홍채 데이터 세트의 열 개수로 인해 위의 코드가 홍채 데이터 세트에서 작동하지만 내 데이터 세트 (두 개의 열만 있음)에서 작동하지 않는지 확실하지 않습니다. 위의 명령을 실행하면 메시지 아래에 나타납니다. thresh = 0.95, k = 5, method = c ("center", : ) 이러한 변수의 분산은 0입니다. – Sourabh
다음 문장을 시도했지만 오류 메시지 : knControl = trainControl (method = "cv", number = 5, .classProbs = FALSE) knnFit1 <- train (Category ~ Text, data = x, method = "knn", preProcess = NULL, 오류 메시지 : 결과에있는 하나 이상의 요인 수준에는 데이터가 없습니다. 모든 요인을 살펴 보았지만 공백/빈 수준을 찾지 못했습니다. – Sourabh