作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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/
我正在使用 R 中的 Caret 包来训练多层感知器 (mlpML) 模型。 我想做的是前向特征消除技术,并了解 mlpML 模型如何针对不同数量的特征执行。 这就是为什么我在循环中训练 mlpML
我是一名优秀的程序员,十分优秀!