gpt4 book ai didi

R(插入符)- 在循环中训练 "mlpML"模型时出错

转载 作者:行者123 更新时间:2023-11-30 09:48:18 25 4
gpt4 key购买 nike

我正在使用 R 中的 Caret 包来训练多层感知器 (mlpML) 模型。

我想做的是前向特征消除技术,并了解 mlpML 模型如何针对不同数量的特征执行。

这就是为什么我在循环中训练 mlpML 模型,其中每次迭代都会添加一个新功能并将其输入到模型中。

这是我得到的错误 -

Error: Please use column names for `x`

这是我的代码 -

ig_features <- c("F1", "F2", "F3", "F4", "F5")

library(caret)

x_features <- c()

for (i in ig_features) {

x_features <- c(x_features, i)
y_features <- c("Status")

#------------------------------------------ Building Model ---------------------------------------------------
set.seed(1234)

mlp_grid = expand.grid(layer1 = 10,
layer2 = 10,
layer3 = 10)

mlp_fit = caret::train(x = TRAIN[,x_features],
y = TRAIN[,y_features],
method = "mlpML",
preProc = c('center', 'scale', 'knnImpute', 'pca'),
trControl = trainControl(method = "cv", verboseIter = TRUE, returnData = FALSE),
tuneGrid = mlp_grid)

#------------------------------------------ Prediction & Evaluation -----------------------------------------
predictions <- predict(mlp_fit, newdata=TEST[,x_features])

cat("Accuracy:",confusionMatrix(predictions,
PARKINSON_TRAIN$Status,
dnn = c("Prediction", "Actual"),
positive="1")$overall[[1]],"\n")
}

最佳答案

您缺少 x 的列名称,在本例中为 TRAIN[,x_features]。请参阅 ?caret::train 文档,其中指出:

x: For the default method, x is an object where samples are in rows and features are in columns. This could be a simple matrix, data frame or other type (e.g. sparse matrix) but must have column names (see Details below).

关于R(插入符)- 在循环中训练 "mlpML"模型时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49411147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com