标签: random-forest

randomForest和long向量的问题

我在一个包含8个数字列(预测变量)和1个因子(结果)的数据集上运行随机林.数据集中有1.2M行.当我做:

randomForest(outcome.f ~ a + b + c + d + e + f + g + h,data=mdata)),我收到一个错误:

"Error in randomForest.default(m, y, ...) : 
 long vectors (argument 26) are not supported in .Fortran"
Run Code Online (Sandbox Code Playgroud)

有什么方法可以防止这种情况吗?我不明白为什么包(显然)试图分配长度为2 ^ 31-1的向量.我使用的是Mac OS X 10.9.2,带有Intel Core i7(如果架构很重要).

会话信息

R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] randomForest_4.6-7

loaded via a namespace (and not attached):
[1] tools_3.1.0
Run Code Online (Sandbox Code Playgroud)

r random-forest

12
推荐指数
1
解决办法
4887
查看次数

为sklearn算法选择random_state

据我所知,random_state在各种sklearn算法中使用它来打破具有相同度量值的不同预测变量(树)之间的联系(例如在中GradientBoosting).但是文档没有澄清或详细说明.喜欢

1)这些种子用于随机数生成的其他地方?比如说RandomForestClassifier,随机数可用于查找一组随机特征来构建预测器.使用子采样的算法可以使用随机数来获得不同的子样本.可以/是同一种子(random_state)在多个随机数生成中扮演一个角色吗?

我主要关心的是

2)这个random_state变量的影响有多远.?这个值能否在预测(分类或回归)方面产生很大的不同.如果是,我应该关注哪种数据集?或者更多的是关于稳定性而不是结果的质量?

3)如果它可以产生很大的不同,如何最好地选择random_state?没有直觉,很难做GridSearch.特别是如果数据集是这样的,一个CV可能需要一个小时.

4)如果动机只是在重复运行中只有稳定的结果/评估我的模型和交叉验证分数,如果我random.seed(X)在使用任何算法之前设置(并使用random_state无),它是否具有相同的效果.

5)假设我random_state在GradientBoosted分类器上使用了一个值,并且我正在交叉验证以找到我的模型的优点(每次都在验证集上得分).一旦满意,我将在整个训练集上训练我的模型,然后将其应用于测试集.现在,完整的训练集比交叉验证中的较小训练集具有更多的实例.因此,random_state与cv循环中发生的情况相比,该值现在可以导致完全不同的行为(特征和个体预测变量的选择).类似于像样本叶子等的事情也可能导致较差的模型,因为设置是CV中的实例数,而实际的实例数更多.这是正确的理解吗?防范这种情况的方法是什么?

machine-learning random-forest scikit-learn

12
推荐指数
1
解决办法
5844
查看次数

游侠的重要性

我用caret+ 训练了一个随机森林ranger.

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'
)
Run Code Online (Sandbox Code Playgroud)

现在我想看看变量的重要性.但是,这些都不起作用:

> importance(fit)
Error in UseMethod("importance") : no applicable method for 'importance' applied to an object of class "c('train', 'train.formula')"
> fit$variable.importance
NULL
> fit$importance
NULL

> fit
Random Forest 

217380 samples
    32 predictors

No pre-processing
Resampling: Cross-Validated (5 …
Run Code Online (Sandbox Code Playgroud)

r machine-learning random-forest r-caret

12
推荐指数
3
解决办法
1万
查看次数

在R中组合使用不同训练集构建的随机森林

我是R的新手(第2天),他的任务是建造一片随意的森林.每个随机森林将使用不同的训练集建立,我们将结束所有森林进行预测.我在R中实现这个,并且在使用不使用相同集合构建的两个森林时遇到一些困难.我的尝试如下:

d1 = read.csv("../data/rr/train/10/chunk0.csv",header=TRUE)
d2 = read.csv("../data/rr/train/10/chunk1.csv",header=TRUE)

rf1 = randomForest(A55~., data=d1, ntree=10)
rf2 = randomForest(A55~., data=d2, ntree=10)

rf = combine(rf1,rf2)
Run Code Online (Sandbox Code Playgroud)

这当然会产生错误:

Error in rf$votes + ifelse(is.na(rflist[[i]]$votes), 0, rflist[[i]]$votes) : 
non-conformable arrays
In addition: Warning message:
In rf$oob.times + rflist[[i]]$oob.times :
longer object length is not a multiple of shorter object length
Run Code Online (Sandbox Code Playgroud)

我已经浏览网页一段时间了解这一点,但尚未取得任何成功.这里的任何帮助将非常感激.

statistics r machine-learning random-forest

11
推荐指数
1
解决办法
8251
查看次数

如何从python输出RandomForest分类器?

我已经使用非常大的数据集训练了一个来自Python Sckit Learn Module的RandomForestClassifier,但问题是我怎么可能保存这个模型并让其他人在它们的末尾应用它.谢谢!

python random-forest scikit-learn

11
推荐指数
2
解决办法
8870
查看次数

sklearn是否支持成本矩阵?

是否有可能使用成本矩阵训练sklearn中的分类器,并为不同的错误提供不同的成本?例如,在2类问题中,成本矩阵将是2乘2平方矩阵.例如,A_ij =将i分类为j的成本.

我使用的主要分类器是随机森林.

谢谢.

classification random-forest scikit-learn

11
推荐指数
1
解决办法
3483
查看次数

cross_val_score与scoring ='roc_auc'和roc_auc_score有什么区别?

我对cross_val_score评分指标'roc_auc'和我可以直接导入和调用的roc_auc_score之间的区别感到困惑.

文档(http://scikit-learn.org/stable/modules/model_evaluation.html#scoring-parameter)表明指定scoring ='roc_auc'将使用sklearn.metrics.roc_auc_score.但是,当我使用scoring ='roc_auc'实现GridSearchCV或cross_val_score时,我会收到非常不同的数字,当我直接调用roc_auc_score时.

这是我的代码,以帮助演示我所看到的:

# score the model using cross_val_score

rf = RandomForestClassifier(n_estimators=150,
                            min_samples_leaf=4,
                            min_samples_split=3,
                            n_jobs=-1)

scores = cross_val_score(rf, X, y, cv=3, scoring='roc_auc')

print scores
array([ 0.9649023 ,  0.96242235,  0.9503313 ])

# do a train_test_split, fit the model, and score with roc_auc_score

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
rf.fit(X_train, y_train)

print roc_auc_score(y_test, rf.predict(X_test))
0.84634039111363313 # quite a bit different than the scores above!
Run Code Online (Sandbox Code Playgroud)

我觉得我在这里错过了一些非常简单的事情 - 很可能是我如何实施/解释其中一个评分指标的错误.

任何人都可以解释两个得分指标之间差异的原因吗?

python machine-learning random-forest scikit-learn cross-validation

11
推荐指数
2
解决办法
1万
查看次数

R:从h2o.randomForest()和h2o.gbm()绘制树

寻找一种有效的方法在rstudio,H2O的Flow或h2o的RF和GBM模型的本地html页面中绘制树,类似于下面链接中的图像.具体来说,如何通过解析h2o.download_pojo(rf1)或h2o.download_pojo(gbm1)来为下面的代码生成的对象(拟合模型)rf1和gbm2绘制树?

http://i.stack.imgur.com/3OWx1.png

# # The following two commands remove any previously installed H2O packages for R.
# if ("package:h2o" %in% search()) { detach("package:h2o", unload=TRUE) }
# if ("h2o" %in% rownames(installed.packages())) { remove.packages("h2o") }

# # Next, we download packages that H2O depends on.
# pkgs <- c("methods","statmod","stats","graphics","RCurl","jsonlite","tools","utils")
# for (pkg in pkgs) {
#   if (! (pkg %in% rownames(installed.packages()))) { install.packages(pkg) }
# }
# 
# # Now we download, install h2o package
# install.packages("h2o", type="source", repos=(c("http://h2o-release.s3.amazonaws.com/h2o/rel-turchin/3/R")))
library(h2o)

h2o.init(nthreads = …
Run Code Online (Sandbox Code Playgroud)

r data-visualization random-forest gbm h2o

11
推荐指数
1
解决办法
6435
查看次数

如何加快随机森林的训练?

我正在尝试训练几个随机森林(用于回归)让他们竞争,看看哪个特征选择和哪个参数给出最佳模型.

然而,训练似乎花了很多时间,我想知道我做错了什么.

我用于训练的数据集(train下面称为)有217k行和58列(其中只有21列作为随机森林中的预测变量.它们都是numeric或者integer,除了布尔值,它是类的charactery输出是numeric).

我跑到下面的代码四次,给值4,100,500,2000nb_trees:

library("randomForest")
nb_trees <- #this changes with each test, see above
ptm <- proc.time()
fit <- randomForest(y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 
    + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 …
Run Code Online (Sandbox Code Playgroud)

parallel-processing r random-forest parallel-foreach doparallel

11
推荐指数
2
解决办法
9855
查看次数

随机森林的varImp(插入符号)和重要性(randomForest)之间的差异

我不明白随机森林模型的varImp函数(caret包)和importance函数(randomForest包)之间的区别是什么:

我计算了一个简单的RF分类模型,当计算变量重要性时,我发现两个函数的预测变量的"排名"并不相同:

这是我的代码:

rfImp <- randomForest(Origin ~ ., data = TAll_CS,
                       ntree = 2000,
                       importance = TRUE)

importance(rfImp)

                                 BREAST       LUNG MeanDecreaseAccuracy MeanDecreaseGini
Energy_GLCM_R1SC4NG3        -1.44116806  2.8918537            1.0929302        0.3712622
Contrast_GLCM_R1SC4NG3      -2.61146974  1.5848150           -0.4455327        0.2446930
Entropy_GLCM_R1SC4NG3       -3.42017102  3.8839464            0.9779201        0.4170445
...

varImp(rfImp)
                                 BREAST        LUNG
Energy_GLCM_R1SC4NG3         0.72534283  0.72534283
Contrast_GLCM_R1SC4NG3      -0.51332737 -0.51332737
Entropy_GLCM_R1SC4NG3        0.23188771  0.23188771
...
Run Code Online (Sandbox Code Playgroud)

我以为他们使用相同的"算法"但我现在不确定.

编辑

为了重现该问题,ionosphere可以使用数据集(kknn包):

library(kknn)
data(ionosphere)
rfImp <- randomForest(class ~ ., data = ionosphere[,3:35],
                       ntree = 2000,
                       importance = TRUE) …
Run Code Online (Sandbox Code Playgroud)

r feature-selection random-forest r-caret

11
推荐指数
2
解决办法
1万
查看次数