然而,一个类似的问题被问到答案中的链接指向随机森林的例子,它似乎在我的情况下不起作用.
这是我正在尝试做的一个例子:
gbmGrid <- expand.grid(interaction.depth = c(5, 9),
n.trees = (1:3)*200,
shrinkage = c(0.05, 0.1))
fitControl <- trainControl(
method = "cv",
number = 3,
classProbs = TRUE)
gbmFit <- train(strong~.-Id-PlayerName, data = train[1:10000,],
method = "gbm",
trControl = fitControl,
verbose = TRUE,
tuneGrid = gbmGrid)
gbmFit
Run Code Online (Sandbox Code Playgroud)
一切顺利,我得到最好的参数.现在,如果我做预测:
predictStrong = predict(gbmFit, newdata=train[11000:50000,])
Run Code Online (Sandbox Code Playgroud)
我得到了一个预测的二元向量,这很好:
[1] 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 1 ...
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试获取概率时,我收到一个错误: …
来自插入符R包的parRF不适合我使用多个核心,这是非常具有讽刺意味的,因为parRF中的par表示并行.我在Windows机器上,如果这是一个相关的信息.我检查过我正在使用最新的关于插入符号和doParallel的最新内容.
我做了一个最小的例子并给出了下面的结果.有任何想法吗?
源代码
library(caret)
library(doParallel)
trCtrl <- trainControl(
method = "repeatedcv"
, number = 2
, repeats = 5
, allowParallel = TRUE
)
# WORKS
registerDoParallel(1)
train(form = Species~., data=iris, trControl = trCtrl, method="parRF")
closeAllConnections()
# FAILS
registerDoParallel(2)
train(form = Species~., data=iris, trControl = trCtrl, method="parRF")
closeAllConnections()
Run Code Online (Sandbox Code Playgroud)
产量
> library(caret)
> library(doParallel)
>
> trCtrl <- trainControl(
+ method = "repeatedcv"
+ , number = 2
+ , repeats = 5
+ , allowParallel = TRUE
+ …Run Code Online (Sandbox Code Playgroud) 我是CARET包的新手.我想知道它如何用于预测多变量时间序列数据.
data(economics)
library(caret)
library(kernlab)
myTimeControl <- trainControl(method = "timeslice", initialWindow =200,horizon =50, fixedWindow = TRUE)
svmRbftune <- train(unemploy ~ pce + pop + psavert + uempmed,
data = economics[1:250,], method = "svmRadial",
tunelength = 14, trControl = myTimeControl)
svmpredict<-predict(svmRbftune,economics[251:350,])
Run Code Online (Sandbox Code Playgroud)
但是,我们怎么能预测这里的前进一步
我一直在使用GBM通过插入符号没有问题,但是从我的数据框中删除一些变量,当它开始失败.我已经尝试了所提到的包的github和cran版本.
这是错误:
> fitRF = train(my_data[trainIndex,vars_for_clust], clusterAssignment[trainIndex], method = "gbm", verbose=T)
Something is wrong; all the Accuracy metric values are missing:
Accuracy Kappa
Min. : NA Min. : NA
1st Qu.: NA 1st Qu.: NA
Median : NA Median : NA
Mean :NaN Mean :NaN
3rd Qu.: NA 3rd Qu.: NA
Max. : NA Max. : NA
NA's :9 NA's :9
Error in train.default(my_data[trainIndex, vars_for_clust], clusterAssignment[trainIndex], :
Stopping
In addition: There were 50 or more warnings …Run Code Online (Sandbox Code Playgroud) 我希望能够从我使用包插入符创建的模型中生成置信区间.这可以在predict(model, data, interval = "confidence")创建模型时使用lm().但是,当我使用插入符train()函数创建的模型尝试相同的命令时,我收到以下错误:
Error in extractPrediction(list(object), unkX = newdata, unkOnly = TRUE, :
unused argument (interval = "confidence")
Run Code Online (Sandbox Code Playgroud)
即使我method = "lm"在train函数中设置也是如此.有谁知道如何从这样的对象获得置信区间?优选使用,predict因此格式相同.
谢谢!
我之前见过其他人有这个错误,但是,我还没有找到满意的答案.我想知道是否有人能对我的问题提供一些见解?
我有一些汽车拍卖数据,我试图建模,以预测Hammer.Price.
> str(myTrain)
'data.frame': 34375 obs. of 9 variables:
$ Grade : int 4 4 4 4 2 3 4 3 3 4 ...
$ Mileage : num 150850 113961 71834 57770 43161 ...
$ Hammer.Price : num 750 450 1600 4650 4800 ...
$ New.Price : num 15051 13795 15051 14475 14475 ...
$ Year.Introduced: int 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 ...
$ Engine.Size : num 1.6 1.6 1.6 1.6 1.6 …Run Code Online (Sandbox Code Playgroud) 你好我的findCorrelation()函数有问题,这是我的输入和输出:
findCorrelation(train, cutoff = .50, verbose = FALSE)
Run Code Online (Sandbox Code Playgroud)
findCorrelation_exact出错(x = x,cutoff = cutoff,verbose = verbose):相关矩阵不对称
有谁知道为什么会这样?
我createFolds()在R(版本:3.3.0)中使用来创建训练/测试分区.为了使结果可重复,我使用set.seed()种子值为10.正如预期的那样,结果(生成的折叠)是可重复的.
但是,一旦我在设定种子之后加载了插入包.然后使用createFolds函数,我发现创建的折叠是不同的(虽然仍然可以重现).
具体而言,创建的折叠在以下两种情况下有所不同:
情况1:
library(caret)
set.seed(10)
folds=createFolds(y,k=5,returnTrain=TRUE)
Run Code Online (Sandbox Code Playgroud)
案例2:
set.seed(10)
library(caret)
folds=createFolds(y,k=5,returnTrain=TRUE)
Run Code Online (Sandbox Code Playgroud)
哪里y是矢量.
为什么会发生这种情况?
从文档:
对于自举样本,使用简单的随机采样.
对于其他数据分割,当y是试图平衡分裂内的类分布的因素时,随机采样在y的水平内完成.
对于数字y,样本基于百分位数分组为组,并且在这些子组内进行采样.
对于createDataPartition,百分位数通过groups参数设置.
我不明白为什么需要这种"平衡"的东西.我认为我从表面上理解它,但任何额外的见解都会非常有用.
我正在使用插入包来分析使用游侠构建的随机森林模型.我无法弄清楚如何使用tuneGrid参数调用train函数来调整模型参数.
我想我调用了tuneGrid参数是错误的,但是无法弄清楚为什么它是错误的.任何帮助,将不胜感激.
data(iris)
library(ranger)
model_ranger <- ranger(Species ~ ., data = iris, num.trees = 500, mtry = 4,
importance = 'impurity')
library(caret)
# my tuneGrid object:
tgrid <- expand.grid(
num.trees = c(200, 500, 1000),
mtry = 2:4
)
model_caret <- train(Species ~ ., data = iris,
method = "ranger",
trControl = trainControl(method="cv", number = 5, verboseIter = T, classProbs = T),
tuneGrid = tgrid,
importance = 'impurity'
)
Run Code Online (Sandbox Code Playgroud)