我试图将 logLoss 合并为通过插入符号(而不是默认选项 Accuracy 或 Kappa)调整 randomForest(其他分类器)时使用的性能度量。
第一个 R 脚本使用默认值执行,不会出现错误。但是,我得到:
{ 中的错误:任务 1 失败 - “未使用的参数(模型 = 方法)”
使用第二个脚本时。
该函数logLoss(predict(rfModel,test[,-c(1,95)],type="prob"),test[,95])通过利用单独训练的随机森林模型来工作。
该数据框有 100 多列和 10,000 多行。所有元素都是在 col=95 的 9 级分类“目标”之外的数字。行 id 位于 col=1 中。
不幸的是,我没有正确掌握http://topepo.github.io/caret/training.html提供的指导,也没有通过谷歌搜索获得太多运气。
非常感谢您的帮助。
工作 R 脚本:
fitControl = trainControl(method = "repeatedcv",number = 10,repeats = 10)
rfGrid = expand.grid(mtry=c(1,9))
rfFit = train(target ~ ., data = train[,-1],method = "rf",trControl = fitControl,verbose = FALSE,tuneGrid = rfGrid)
Run Code Online (Sandbox Code Playgroud)
R 脚本不工作:
logLoss = function(data,lev=NULL,method=NULL) {
lLoss = 0
epp = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在caret包中应用基于过滤器的特征选择以进行逻辑回归.我成功地使用sbf()随机森林和LDA模型的功能(分别使用rfSBF和ldaSBF).
我修改的方式lmSBF如下:
# custom lmSBF
logisticRegressionWithPvalues <- lmSBF
logisticRegressionWithPvalues$score <- pScore
logisticRegressionWithPvalues$summary <- fiveStats
logisticRegressionWithPvalues$filter <- pCorrection
logisticRegressionWithPvalues$fit <- glmFit
# my training control parameters for sbf (selection by filter)
myTrainControlSBF = sbfControl(method = "cv",
number = 10,
saveDetails = TRUE,
verbose = FALSE,
functions = logisticRegressionWithPvalues)
# fit the logistic regression model
logisticRegressionModelWithSBF <- sbf(x = input_predictors,
y = input_labels,
sbfControl = myTrainControlSBF)
Run Code Online (Sandbox Code Playgroud)
这里,glmFit功能(如上所述)如下:
# fit function …Run Code Online (Sandbox Code Playgroud) 我有一个56 列的training_predictors集合,所有这些都是. 是一个的矢量和。numerictraining_labelsfactor01
我使用以下列表作为要测试的子集大小。
subset_sizes <- c(1:5, 10, 15, 20, 25)
Run Code Online (Sandbox Code Playgroud)
以下是修改后的列表 rfFuncs函数。
rfRFE <- list(summary = defaultSummary,
fit = function(x, y, first, last, ...) {
library(randomForest)
randomForest(x, y, importance = first, ...)
},
pred = function(object, x) predict(object, x),
rank = function(object, x, y) {
vimp <- varImp(object)
vimp <- vimp[order(vimp$Overall, decreasing = TRUE),,drop = FALSE]
vimp$var <- rownames(vimp)
vimp
},
selectSize = pickSizeBest,
selectVar = pickVars)
Run Code Online (Sandbox Code Playgroud)
我已将控制函数声明为:
rfeCtrl …Run Code Online (Sandbox Code Playgroud) 我在R中有一个data.table,我想用插入包
set.seed(42)
trainingRows<-createDataPartition(DT$variable, p=0.75, list=FALSE)
head(trainingRows) # view the samples of row numbers
Run Code Online (Sandbox Code Playgroud)
但是,我无法使用data.table选择行.相反,我必须转换为data.frame
DT_df <-as.data.frame(DT)
DT_train<-DT_df[trainingRows,]
dim(DT_train)
Run Code Online (Sandbox Code Playgroud)
data.table替代方案
DT_train <- DT[.(trainingRows),] requires the keys to be set.
Run Code Online (Sandbox Code Playgroud)
除了转换为data.frame之外还有更好的选择吗?
我收到以下错误,我不知道可能出了什么问题.我正在使用R Studio和3.1.3版本的R for Windows 8.1并使用Caret包进行数据挖掘.
我有以下培训数据:
str(training)
'data.frame': 212300 obs. of 21 variables:
$ FL_DATE_MDD_MMDD : int 101 101 101 101 101 101 101 101 101 101 ...
$ FL_DATE : int 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 ...
$ UNIQUE_CARRIER : Factor w/ 13 levels "9E","AA","AS",..: 11 10 2 5 8 9 11 10 10 10 ...
$ DEST : Factor w/ 150 levels "ABE","ABQ","ALB",..: 111 70 82 8 8 31 110 44 53 80 …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装该软件包caret在 R 中安装该包一段时间,但收到此错误消息:
*installing *source* package \xe2\x80\x98minqa\xe2\x80\x99 ...\n** package \xe2\x80\x98minqa\xe2\x80\x99 successfully unpacked and MD5 sums checked\n** libs\ngfortran -fpic -g -O2 -c altmov.f -o altmov.o\nmake: gfortran: Command not found\nmake: *** [altmov.o] Error 127\n/usr/lib64/R/etc/Makeconf:155: recipe for target 'altmov.o' failed\nERROR: compilation failed for package \xe2\x80\x98minqa\xe2\x80\x99\n* removing \xe2\x80\x98/home/mohammad/R/x86_64-pc-linux-gnu-library/3.3/minqa\xe2\x80\x99\nWarning in install.packages :\n installation of package \xe2\x80\x98minqa\xe2\x80\x99 had non-zero exit status\n* installing *source* package \xe2\x80\x98SparseM\xe2\x80\x99 ...\n** package \xe2\x80\x98SparseM\xe2\x80\x99 successfully unpacked and MD5 sums checked\n** libs\ngfortran -fpic -g -O2 -c bckslv.f -o bckslv.o\nmake: gfortran: …Run Code Online (Sandbox Code Playgroud) 在插入符号包中,哪些集合模型可用于多类分类?此外,在尝试http://topepo.github.io/caret/Ensemble_Model.html中提到的一些功能时,它给出了:
不在插入符号的内置库中.
Google上的许多功能都没有相关软件包的建议.有谁能帮助我解决这两个问题?
当R caret用于比较同一数据集上的多个模型时,caret如果tuneLength为所有模型指定了相同的范围并且没有指定特定于模型的范围,则足够聪明地为不同的模型选择不同的调整范围tuneGrid。
例如,caret为一个特定数据集选择的调整范围是:
earth(nprune): 2, 5, 8, 11, 14
gamSpline(df): 1, 1.5, 2, 2.5, 3
rpart(cp): 0.010, 0.054, 0.116, 0.123, 0.358
有谁知道如何caret确定这些默认调整范围?我一直在搜索文档,但仍然没有确定选择范围的算法。
我很困惑.我以前用过火车没问题.但现在我反复得到"未使用的参数"错误.
#Generate random data
y <- rnorm(100, mean=.5)
x <- rnorm(100)
data <- cbind(x, y)
form <- y ~ x
fitControl <- trainControl(## 10-fold CV
method = "cv",
number = 8)
set.seed(825)
lmFit1 <- train(x, y, method = "lm", trControl = fitControl, na.action=na.omit)
lmFit1 <- train(form, data = data, method = "lm", trControl = fitControl, na.action=na.omit)
Run Code Online (Sandbox Code Playgroud)
由于我正在运行线性回归,我已经使用x和y以及表单指定了此模型.两者都会产生相同的错误.
Error in train(form, method = "lm", trControl = fitControl, na.action = na.omit) : unused arguments (method = "lm", trControl = fitControl, na.action = …Run Code Online (Sandbox Code Playgroud) 我使用插入符R包作为一个非常方便的建模包装.虽然这是一个奇怪的用途,但在使用模型类型="lm"和交叉验证"无"时,我在从模型中提取结果时遇到一些麻烦.见下面的例子:
library(caret)
## Make data
> Xs <- matrix(rnorm(300*20), nrow = 300, ncol = 20)
> Yvec <- rnorm(300)
## Make traincontrol, cv of "none"
> tcontrol <- trainControl(method = "none")
## Fit lm model using train
> fit <- train(x= Xs, y = Yvec, method = "lm", metric = "RMSE", trControl = tcontrol)
> fit$results
[1] RMSE Rsquared parameter
<0 rows> (or 0-length row.names)
Run Code Online (Sandbox Code Playgroud)
任何想法为什么适合$结果是空的?对于所有其他型号和CV类型,这似乎有效.例如使用2倍CV:
> tcontrol2 <- trainControl(method = "cv", number = 2)
> fit2 <- train(x= Xs, …Run Code Online (Sandbox Code Playgroud)