这是我的代码:
library(shiny)
library(shinydashboard)
library(plotly)
library(readxl)
library(png)
library(xlsx)
library(DT)
library(class)
shinyServer(function(input, output, session){
normalisasi <- function(data){
((data-min(data))/(max(data)-min(data)))
}
datatrain <- read_xlsx("E:/fix/data training.xlsx")
datauji <- read_xlsx("E:/fix/data uji.xlsx")
normtrain <- as.data.frame(lapply(datatrain[,c(4,5,6,7,8,9)],normalisasi))
normuji <- as.data.frame(lapply(datauji[,c(4,5,6,7,8,9)],normalisasi))
labeldata <- datatrain[,3, drop = TRUE]
labeltarget <- datauji[,3]
prediksi <- knn(train=normtrain,test=normuji,cl=labeldata, k=input$nilaik)
hasilknn <- cbind(normuji, label=as.vector(prediksi))
output$hasil <- renderDataTable({
table(labeltarget,prediksi)
})
})
但是我遇到了这个错误。
knn中的错误(train = normtrain,test = normuji,cl = labeldata,k = input $ nilaik)'train'和'class'的长度不同
为什么?请!帮助