gpt4 book ai didi

r - 从 R 中经过训练的 randomForest 获取因子水平

转载 作者:行者123 更新时间:2023-12-04 11:02:44 25 4
gpt4 key购买 nike

我在 R 中有一个训练有素的 randomForest 模型,我从 RDS 文件加载。其中一个预测因子是无序因子,我不再拥有用于产生此因子的训练数据,但想知道该因子具有哪些级别,因此我可以确保我尝试预测的数据仅具有这些级别对于这个因素。这可能吗?

最佳答案

randomForest 的数据结构对象略有不同,具体取决于它是使用“公式接口(interface)”还是“矩阵接口(interface)”进行训练的。但是,关于自变量的信息在两种情况下都存储为列表对象 randomForest$forest$xlevels .

library("randomForest")

df = read.csv("Audit.csv")

rf = randomForest(Adjusted ~ ., data = df)
print(rf$forest$xlevels)
print(rf$forest$xlevels["Education"])

关于r - 从 R 中经过训练的 randomForest 获取因子水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58693369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com