0
遺伝的アルゴリズムを使用するキャレットフィーチャ選択を使用しようとしていますが、エラーメッセージが表示されています。私のコードは以下の通りです:フィーチャ選択を使用した遺伝的アルゴリズム
set.seed(10)
trainIndex <- createDataPartition(iris$Species, p = .5, list = FALSE, times = 1)
trainData <- iris[trainIndex,-c(1,2)]
testData <- iris[-trainIndex,-c(1,2)]
trainX <-trainData[,-1]
testX <- testData[,-1]
y=trainData$Class
data(iris)
dim(iris)
# [1] 150 5
head(iris,2)
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1 5.1 3.5 1.4 0.2 setosa
# 2 4.9 3.0 1.4 0.2 setosa
registerDoParallel(4)
getDoParWorkers() [1] 4
utils:::menuInstallLocal()
# le package ‘GA’ a été décompressé et les sommes MD5 ont été vérifiées avec succés
ga_ctrl <- gafsControl(functions = rfGA, method = "cv", genParallel=TRUE, allowParallel = TRUE)
set.seed(10)
lev <- c("PS","WS")
system.time(rf_ga3 <- gafs(x = trainX, y = y, iters = 100, popSize = 20, levels = lev, gafsControl = ga_ctrl))
# Erreur dans gafs.default(x = trainX, y = y, iters = 100, popSize = 20, levels = lev, :
# there should be the same number of samples in x and y Timing stopped at: 0 0 0
あなたの 'y'ベクトルのサイズが間違っているようです。 XをサンプリングしてYのサンプルも忘れているかもしれません。 – Fernando
Rania様、ご質問の書式設定に何らかの努力をしてください。あなたの質問に答えるために:@フェルナンドは正しい、あなたが完全なyを使っているのは、xが訓練のためにインデックスだけを使うからです。そこには間違いがあります。 – Drey