В сообщении об ошибке говорится, что поезд и класс не имеют одинаковых размеров, хотя dim()
показывает обратное.
library(dataPreparation)
encoding <- build_encoding(dataSet = Data.train, cols = "auto", verbose = TRUE)
data.train <- one_hot_encoder(dataSet = Data.train, encoding = encoding, drop = TRUE, verbose = TRUE)
Data.test <- one_hot_encoder(dataSet = Data.test, encoding = encoding, drop = TRUE, verbose = TRUE)
bijections <- whichAreBijection(dataSet = data.train, verbose = TRUE)
Data.test <- model.matrix(~ churnn[,1]+churnn[,2]+churnn[,3]+churnn[,4]+churnn[,5]+churnn[,6]+churnn[,7]+churnn[,8]+churnn[,9]+churnn[,10]+churnn[,11]+churnn[,12]+churnn[,13]+churnn[,14]+churnn[,15])
Data.train<- model.matrix(~ churnn[,1]+churnn[,2]+churnn[,3]+churnn[,4]+churnn[,5]+churnn[,6]+churnn[,7]+churnn[,8]+churnn[,9]+churnn[,10]+churnn[,11]+churnn[,12]+churnn[,13]+churnn[,14]+churnn[,15])
dim(cl.test)
dim(Data.train)
[1] 150 27
[1] 150 27
predict.test=knn(train= Data.train,test= Data.test,cl= cl.train,k = 7 )
Error in knn(train = Data.train, test = Data.test, cl = cl.train, k = 7) : 'train' et 'class' ont des longueurs différentes