【问题标题】:Gridsearch in randomforest (RandomForestSRC)随机森林中的网格搜索 (RandomForestSRC)
【发布时间】:2022-01-04 01:17:58
【问题描述】:

我正在使用 RandomForestSRC 来创建使用回归的随机森林模型,并且我想对最优 mtry、nodesize、ntrees、nodedepth 组合执行网格搜索,以便更好地可视化优化过程。

我尝试了以下方法:

mtry <- c(4,8,16)
nodesize <- c(50,150,300)
ntrees <- c(500,1000,2000)
nodedepth <- c(5,10)

frmodel <- rfsrc(mort_30 ~ variable1+variable2+variable3, #(ect)
data= data.train, mtry= mtry, nodesize= nodesize, ntrees=ntrees,
nodedepth=nodedepth, blocksize=1, importance=TRUE, seed=40)

但我不断收到此错误:

I if (mtry < 1 | mtry >n.xvar) mtry <- max(1, min(mtry, n.xvar)):
the condition has length > 1 and only the first element will be used

似乎我无法为这些分配多个值。除了为每个组合手动制作一棵树之外,还有其他方法吗?

【问题讨论】:

    标签: r random-forest grid-search


    【解决方案1】:

    您可以使用 tune 搜索 mtry 和 nodesize,然后可能只为不同的 ntrees 运行它,例如:

    nodesize <- c(5,10,20)
    
    model <- tune(Ozone ~ .,data = airquality,
    mtryStart = 2,
    nodesizeTry= nodesize, ntreeTry=100,
    blocksize=1, importance=TRUE, seed=40)
    
    model$results
       nodesize mtry       err
    1         5    1 0.5750139
    2         5    2 0.4420183
    3         5    3 0.3750303
    4         5    4 0.3781430
    5         5    5 0.3255283
    6        10    1 0.6128187
    7        10    2 0.4719501
    8        10    3 0.3825911
    9        10    4 0.3771207
    10       10    5 0.3523660
    11       20    1 0.6981993
    12       20    2 0.5251094
    13       20    3 0.4451690
    14       20    4 0.4305362
    15       20    5 0.4099460
    

    【讨论】:

      猜你喜欢
      • 2017-12-29
      • 2019-05-06
      • 2019-06-09
      • 2021-03-27
      • 2016-07-23
      • 2021-03-30
      • 1970-01-01
      • 2017-06-13
      • 2015-09-16
      相关资源
      最近更新 更多