- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Party 包运行随机森林模型。我想使用 varimp
函数来确定条件变量的重要性,但它似乎不接受分类变量。这是一个link到我的数据,下面是我正在使用的代码。
> #set up dataframe
> bll = read.csv("bll_Nov2013.csv", header=TRUE)
> SB_Pres <- bll$Sandbar_Presence #binary presence/absnece
> Slope <-bll$Slope
> Dist2Shr <-bll$Dist2Shr
> Bathy <-bll$Bathy2
> Chla <-bll$GSM_Chl_Daily_MF
> SST <-bll$SST_PF_daily
> Region <- bll$Region
> MoonPhase <-bll$MoonPhase
> DaylightHours <- bll$DaylightHours
> bll_SB <- na.omit(data.frame(SB_Pres, Slope, Dist2Shr, Bathy, Chla, SST, DaylightHours, MoonPhase, Region))
> #run cforest model
> SBcf<- cforest(formula = factor(SB_Pres) ~ SST + Chla + Dist2Shr+ DaylightHours + Bathy + Slope + MoonPhase + factor(Region), data = bll_SB, control = cforest_unbiased())
> SBcf
Random Forest using Conditional Inference Trees
Number of trees: 500
Response: factor(SB_Pres)
Inputs: SST, Chla, Dist2Shr, DaylightHours, Bathy, Slope, MoonPhase, factor(Region)
Number of observations: 534
> #Varimp works if conditional = FALSE
> varimp(SBcf, conditional = FALSE)
SST Chla Dist2Shr DaylightHours Bathy Slope
0.024744898 0.084244898 0.015632653 0.009571429 0.006448980 0.003357143
MoonPhase factor(Region)
0.002724490 0.095000000
> #Varimp does NOT work if conditional = TRU
> varimp(SBcf, conditional = TRUE)
Error in model.frame.default(formula = ~SST + Chla + Dist2Shr + DaylightHours + :
variable lengths differ (found for 'factor(Region)')
如果我删除 factor(Region)
变量,则可以计算条件变量重要性。
这是带有分类预测变量的派对包 varimp
函数的已知行为吗?根据我的阅读,它应该能够处理分类预测变量 ( Conditional variable importance for random forests - Strobl et al ) - 它没有明确说明 varimp(obj, conditional = TRUE)
可以与分类预测变量一起使用。
任何见解将不胜感激!
谢谢,
丽莎
编辑:说明如果您在公式之外使用 as.factor 定义变量,则 as.factor 实际上不会生效 - 无论区域是否指定为因子,结果都是相同的。将这些结果与上面运行的其他 varimp (conditional = false) 进行比较,其中输出将变量显示为“factor(Region)”,而在下面它在两次运行中仅显示为“Region”。
> library("party")
> packageDescription("party")$Version
[1] "1.0-10"
> bll = read.csv("bll_SB.csv", header=TRUE)
> bll_SB <- na.omit(data.frame(bll))
> # region is specified as a factor
> bll_SB$SB_Pres <- factor(bll_SB$SB_Pres)
> bll_SB$Region <- factor(bll_SB$Region)
> set.seed(1)
> SBcf <- cforest(SB_Pres ~ ., data=bll_SB, control=cforest_unbiased())
> SBcf
Random Forest using Conditional Inference Trees
Number of trees: 500
Response: SB_Pres
Inputs: Slope, Dist2Shr, Bathy, Chla, SST, DaylightHours, MoonPhase, Region
Number of observations: 534
> system.time(res1 <- varimp(SBcf, conditional = FALSE))
user system elapsed
4.466 0.013 4.480
> res1
Slope Dist2Shr Bathy Chla SST DaylightHours
0.003632653 0.015908163 0.008285714 0.085367347 0.028846939 0.009520408
MoonPhase Region
0.002969388 0.093061224
> # Run again, region is not specified as a factor
> bll_SB$Region <- bll_SB$Region
> set.seed(1)
> SBcf <- cforest(SB_Pres ~ ., data=bll_SB, control=cforest_unbiased())
> system.time(res2 <- varimp(SBcf, conditional = FALSE))
user system elapsed
4.562 0.015 4.578
> res2
Slope Dist2Shr Bathy Chla SST DaylightHours
0.003632653 0.015908163 0.008285714 0.085367347 0.028846939 0.009520408
MoonPhase Region
0.002969388 0.093061224
最佳答案
我无法在您的示例中观察到问题。我能够使用以下代码计算您的数据集的条件变量重要性:
R> library("party")
R> packageDescription("party")$Version
[1] "1.0-10"
R> bll = read.csv("bll_SB.csv", header=TRUE)
R>
R> bll_SB <- na.omit(data.frame(bll))
R> bll_SB$SB_Pres <- factor(bll_SB$SB_Pres)
R> bll_SB$Region <- factor(bll_SB$Region)
R>
R> set.seed(1)
R> SBcf <- cforest(SB_Pres ~ ., data=bll_SB, control=cforest_unbiased())
R> SBcf
#
# Random Forest using Conditional Inference Trees
#
# Number of trees: 500
#
# Response: SB_Pres
# Inputs: Slope, Dist2Shr, Bathy, Chla, SST, DaylightHours, MoonPhase, Region
# Number of observations: 534
R> system.time(res1 <- varimp(SBcf, conditional = FALSE))
# user system elapsed
# 5.971 0.012 5.994
R> system.time(res2 <- varimp(SBcf, conditional = TRUE))
# user system elapsed
# 2704.1 58.2 2768.0
R> res1
# Slope Dist2Shr Bathy Chla SST
# 0.003633 0.015908 0.008286 0.085367 0.028847
# DaylightHours MoonPhase Region
# 0.009520 0.002969 0.093061
R> res2
# Slope Dist2Shr Bathy Chla SST
# -6.122e-05 2.449e-03 -4.082e-05 1.004e-02 3.367e-03
# DaylightHours MoonPhase Region
# 5.714e-04 6.735e-04 1.067e-02
关于r - cforest varimp 似乎不适用于分类预测变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20343974/
我正在尝试使用 Pandas 和 scikit-learn 在 Python 中执行分类。我的数据集包含文本变量、数值变量和分类变量的混合。 假设我的数据集如下所示: Project Cost
我想要一种图形化且有吸引力的方式来表示二进制数据的列总和,而不是表格格式。我似乎无法让它发挥作用,尽管有人会认为这将是一次上篮。 数据看起来像这样(我尝试创建一个可重现的示例,但无法让代码填充 0 和
我有一个简单的类别模型: class Category(models.Model): name = models.CharField(max_length=200) slug = mo
我正在开发一个知识系统,当用户进入一道菜时,该系统可以返回酒。我的想法是根据用户的输入为每个葡萄酒类别添加分数,然后显示最适合的葡萄酒类别的前 3 个。例如,如果有人输入鱼,那么知识库中的所有红葡萄酒
我目前正在研究流失问题的预测模型。 每当我尝试运行以下模型时,都会收到此错误:至少一个类级别不是有效的 R 变量名称。这将在生成类概率时导致错误,因为变量名称将转换为 X0、X1。请使用可用作有效 R
如何对栅格重新分类(子集)r1 (与 r2 具有相同的尺寸和范围)基于 r2 中的以下条件在给定的示例中。 条件: 如果网格单元格值为 r2是 >0.5 ,保留>0.5中对应的值以及紧邻0.5个值的相
我想知道在 java 中进行以下分类的最佳方法是什么。例如,我们有一个简单的应用程序,其分类如下: 空气 -----电机类型 -----------平面对象 -----非电机型 -----------
这是一个非常基本的示例。但我正在做一些数据分析,并且不断发现自己编写非常类似的 SQL 计数查询来生成概率表。 我的表被定义为值 0 表示事件未发生,而值 1 表示事件确实发生。 > sqldf(
假设我有一组护照图像。我正在开展一个项目,我必须识别每本护照上的姓名,并最终将该对象转换为文本。 对于标签(或分类(我认为是初学者))的第一部分,每本护照上都有姓名,我该怎么做? 我可以使用哪些技术/
我有这张图片: 我想做的是在花和树之间对这张图片进行分类,这样我就可以找到图片中被树木覆盖的区域,以及被那些花覆盖的区域。 我在想这可能是某种 FFT 问题,但我不确定它是如何工作的。单个花的 FFT
我的数据集有 32 个分类变量和一个数值连续变量(sales_volume) 首先,我使用单热编码 (pd.get_dummies) 将分类变量转换为二进制,现在我有 1294 列,因为每一列都有多个
我正在尝试学习一些神经网络来获得乐趣。我决定尝试从 kaggle 的数据集中对一些神奇宝贝传奇卡进行分类。我阅读了文档并遵循了机器学习掌握指南,同时阅读了媒体以尝试理解该过程。 我的问题/疑问:我尝试
我目前正在进行推文情绪分析,并且有几个关于步骤的正确顺序的问题。请假设数据已经过相应的预处理和准备。所以这就是我将如何进行: 使用 train_test_split(80:20 比例)停止测试数据集。
一些上下文:Working with text classification and big sparse matrices in R 我一直在研究 text2vec 的文本多类分类问题。包装和 ca
数据 我有以下(简化的)数据集,我们称之为 df从现在开始: species rank value 1
我一直在尝试创建一个 RNN。我总共有一个包含 1661 个单独“条目”的数据集,每个条目中有 158 个时间序列坐标。 以下是一个条目的一小部分: 0.00000000e+00 1.9260968
我有一个关于机器学习的分类和回归问题。第一个问题,以下数据集 http://it.tinypic.com/view.php?pic=oh3gj7&s=8#.VIjhRDGG_lF 我们可以说,数据集是
我用1~200个数据作为训练数据,201~220个作为测试数据格式如下:3 个类(类 1、类 2、类 3)和 20 个特征 2 1:100 2:96 3:88 4:94 5:96 6:94 7:72
我有 2 个基于多个数字特征(例如 v1….v20)的输出类别(好和差)。 如果 v1、v2、v3 和 v4 为“高”,则该类别为“差”。如果 v1、v2、v3 和 v4 为“低”,则该类别为“好”
我遇到了使用朴素贝叶斯将文档分类为各种类别问题的问题。 实际上我想知道 P(C) 或我们最初掌握的类别的先验概率会随着时间的推移而不断变化。例如,对于类(class) - [音乐、体育、新闻] 初始概
我是一名优秀的程序员,十分优秀!