簡體   English   中英

使用插入符號時,createGrid for RF(randomForest)出現錯誤

[英]Errors with createGrid for rf (randomForest) when using caret

當我嘗試創建參數網格以使用插入符號進行訓練時,出現各種錯誤:

> my_grid <- createGrid("rf")
Error in if (p <= len) { : argument is of length zero

> my_grid <- createGrid("rf", 4)
Error in if (p <= len) { : argument is of length zero

> my_grid <- createGrid("rf", len=4)                                        
Error in if (p <= len) { : argument is of length zero

createGrid的文檔說:

This function creates a data frame that contains a grid of
     complexity parameters specific methods.
Usage:
       createGrid(method, len = 3, data = NULL)
Arguments:
  method: a string specifying which classification model to use. See
          'train' for a full list.
     len: an integer specifying the number of points on the grid for
          each tuning parameter.
    data: the training data (only needed in the case where the 'method'
          is 'cforest', 'earth', 'bagEarth', 'fda', 'bagFDA', 'rpart',
          'svmRadial', 'pam', 'lars2', 'rf' or 'pls'). The outcome
          should be in a column called '.outcome'.

並給出以下示例,它們可以正常工作:

 createGrid("rda", 4)
 createGrid("lm")
 createGrid("nnet")

 ## data needed for SVM with RBF:
 ## Not run:

 tmp <- iris
 names(tmp)[5] <- ".outcome"
 head(tmp)
 createGrid("svmRadial", data = tmp, len = 4)
 ## End(Not run)

這樣做,我在做什么錯?

后續問題:

什么是之間的連接len作為參數傳遞給createGridtuneLength在爭論train lentuneLength可以一起使用嗎? 他們是什么關系?

其他有用的主題:

如果有幫助,這里是描述如何使用一個線程createGridtraincaret插入記號::火車:指定型號代參數

從示例中提取的代碼對我來說很好用(並注意,它可以解決在Rhelp上發布時存在的問題):

tmp <- iris
 names(tmp)[5] <- ".outcome"
 head(tmp)
 createGrid("svmRadial", data = tmp, len = 4)
#-------
     .sigma   .C
1 0.7500934 0.25
2 0.7500934 0.50
3 0.7500934 1.00
4 0.7500934 2.00

編輯:

>  createGrid("rf", data = tmp, len = 4)
randomForest 4.6-7
Type rfNews() to see new features/changes/bug fixes.

Attaching package: ‘randomForest’

The following object(s) are masked from ‘package:Hmisc’:

    combine

note: only 3 unique complexity parameters in default grid. Truncating the grid to 3 .

  .mtry
1     2
2     3
3     4

我再說一遍:還有什么問題?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM