变量重要性与ranger

我使用 caretranger 训练了一个随机森林。

fit <- train(    y ~ x1 + x2    ,data = total_set    ,method = "ranger"    ,trControl = trainControl(method="cv", number = 5, allowParallel = TRUE, verbose = TRUE)    ,tuneGrid = expand.grid(mtry = c(4,5,6))    ,importance = 'impurity')

现在我想查看变量的重要性。然而,以下方法都不起作用:

> importance(fit)Error in UseMethod("importance") : no applicable method for 'importance' applied to an object of class "c('train', 'train.formula')"> fit$variable.importanceNULL> fit$importanceNULL> fitRandom Forest 217380 samples    32 predictorsNo pre-processingResampling: Cross-Validated (5 fold) Summary of sample sizes: 173904, 173904, 173904, 173904, 173904 Resampling results across tuning parameters:  mtry  RMSE        Rsquared   4     0.03640464  0.5378731  5     0.03645528  0.5366478  6     0.03651451  0.5352838RMSE was used to select the optimal model using  the smallest value.The final value used for the model was mtry = 4. 

有谁知道是否以及如何能获取这些信息?

谢谢。


回答:

varImp(fit) 可以帮你获取这些信息。

为了找到这个方法,我查看了 names(fit),这引导我查看了 names(fit$modelInfo) – 然后你会看到 varImp 是其中一个选项。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注