简体   繁体   English

R Caret软件包中的火车功能不断崩溃

[英]train function in R caret package keeps crashing

I am training a kNN model with train function from the R caret package and a dataset of 2000 entries. 我正在从R caret包和2000个条目的数据集中训练带有训练功能的kNN模型。 I used the following code: 我使用以下代码:

set.seed(400)
ctrl <- trainControl(method="none")
knnFit <- train(Class ~ ., data = ScaniaTrain, method = "knn", trControl = ctrl, tuneLength = 1)

but the R keeps crashing. 但是R不断崩溃 How can I improve the performance of this function? 如何改善此功能的性能?

KNN is costly, it may not be possible to train a model if you have lots of columns in your data (or if you have lots of categorical variables that caret expands to dummy variables under the hood). KNN的成本很高,如果您的数据中有很多列(或者如果您有很多分类变量可以将插入符号扩展为底层的虚拟变量),则可能无法训练模型。

You can try to set the k parameter to a low value and see if it works: 您可以尝试将k参数设置为较低的值,看看它是否有效:

knnFit <- train(
  Class ~ ., 
  data = ScaniaTrain, 
  method = "knn", 
  trControl = ctrl,
  tuneGrid = c(k=3)
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM