我正在尝试使用插入包中的列车功能来构建模型:
model <- train(training$class ~ .,data=training, method = "nb")
Run Code Online (Sandbox Code Playgroud)
训练集包含大约20K的观测值,每个观测值都有100个以上的变量.我想知道从该数据集构建模型是否需要数小时或数天.
如何估算从数据中训练模型所需的时间?使用插入包中的功能时如何跟踪培训过程的进度?
我试图使用机器学习来根据时间序列数据进行预测.在其中一个stackoverflow问题(R中的CARET包中的createTimeSlices函数)是使用createTimeSlices进行模型训练和参数调整的交叉验证的示例:
library(caret)
library(ggplot2)
library(pls)
data(economics)
myTimeControl <- trainControl(method = "timeslice",
initialWindow = 36,
horizon = 12,
fixedWindow = TRUE)
plsFitTime <- train(unemploy ~ pce + pop + psavert,
data = economics,
method = "pls",
preProc = c("center", "scale"),
trControl = myTimeControl)
Run Code Online (Sandbox Code Playgroud)
我的理解是:
因为我的数据是时间序列,我想我不能使用bootstraping将数据分成训练和测试集.所以,我的问题是:我是对的吗?如果是这样 - 如何使用createTimeSlices进行模型评估?
我正在解决多类分类问题,并尝试使用广义Boosted模型(R中的gbm包).我遇到的问题:插入符号的train功能method="gbm"似乎不能正确处理多类数据.下面给出一个简单的例子.
library(gbm)
library(caret)
data(iris)
fitControl <- trainControl(method="repeatedcv",
number=5,
repeats=1,
verboseIter=TRUE)
set.seed(825)
gbmFit <- train(Species ~ ., data=iris,
method="gbm",
trControl=fitControl,
verbose=FALSE)
gbmFit
Run Code Online (Sandbox Code Playgroud)
输出是
+ Fold1.Rep1: interaction.depth=1, shrinkage=0.1, n.trees=150
predictions failed for Fold1.Rep1: interaction.depth=1, shrinkage=0.1, n.trees=150
- Fold1.Rep1: interaction.depth=1, shrinkage=0.1, n.trees=150
+ Fold1.Rep1: interaction.depth=2, shrinkage=0.1, n.trees=150
...
+ Fold5.Rep1: interaction.depth=3, shrinkage=0.1, n.trees=150
predictions failed for Fold5.Rep1: interaction.depth=3, shrinkage=0.1, n.trees=150
- Fold5.Rep1: interaction.depth=3, shrinkage=0.1, n.trees=150
Aggregating results
Selecting tuning parameters
Fitting interaction.depth = numeric(0), n.trees = numeric(0), shrinkage = …Run Code Online (Sandbox Code Playgroud) 我试图以任何方式获得射频模型的变量重要性.这是我到目前为止尝试过的方法,但非常欢迎其他建议.
我在R训练了一个模型:
require(caret)
require(randomForest)
myControl = trainControl(method='cv',number=5,repeats=2,returnResamp='none')
model2 = train(increaseInAssessedLevel~., data=trainData, method = 'rf', trControl=myControl)
Run Code Online (Sandbox Code Playgroud)
数据集相当大,但模型运行正常.我可以访问它的部件并运行命令,例如:
> model2[3]
$results
mtry RMSE Rsquared RMSESD RsquaredSD
1 2 0.1901304 0.3342449 0.004586902 0.05089500
2 61 0.1080164 0.6984240 0.006195397 0.04428158
3 120 0.1084201 0.6954841 0.007119253 0.04362755
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
> varImp(model2)
Error in varImp[, "%IncMSE"] : subscript out of bounds
Run Code Online (Sandbox Code Playgroud)
显然应该有一个包装器,但似乎并非如此:(cf:http://www.inside-r.org/packages/cran/caret/docs/varImp)
varImp.randomForest(model2)
Error: could not find function "varImp.randomForest"
Run Code Online (Sandbox Code Playgroud)
但这特别奇怪:
> traceback()
No traceback available
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-redhat-linux-gnu …Run Code Online (Sandbox Code Playgroud) 有人告诉我使用插入包来执行支持向量机回归,对我拥有的数据集进行10倍交叉验证.我正在针对151个变量绘制我的响应变量.我做了以下事情: -
> ctrl <- trainControl(method = "repeatedcv", repeats = 10)
> set.seed(1500)
> mod <- train(RT..seconds.~., data=cadets, method = "svmLinear", trControl = ctrl)
Run Code Online (Sandbox Code Playgroud)
我得到了
C RMSE Rsquared RMSE SD Rsquared SD
0.2 50 0.8 20 0.1
0.5 60 0.7 20 0.2
1 60 0.7 20 0.2
Run Code Online (Sandbox Code Playgroud)
但我希望能够看一下我的折叠,并且对于每个折叠,预测值与实际值的接近程度.我怎么去看这个?
此外,它说: -
RMSE was used to select the optimal model using the smallest value.
The final value used for the model was C = 0.
Run Code Online (Sandbox Code Playgroud)
我只是想知道这意味着什么以及C在上表中代表什么?
RT (seconds) 76_TI2 114_DECC 120_Lop 212_PCD …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PCA作为预处理在插入符号中构建预测模型.预处理如下:
preProc <- preProcess(IL_train[,-1], method="pca", thresh = 0.8)
Run Code Online (Sandbox Code Playgroud)
是否有可能将thresh参数直接传递给插入符号的train()函数?我尝试了以下,但它不起作用:
modelFit_pp <- train(IL_train$diagnosis ~ . , preProcess="pca",
thresh= 0.8, method="glm", data=IL_train)
Run Code Online (Sandbox Code Playgroud)
如果没有,我如何将单独的preProc结果传递给train()函数?
在R中,我指定一个没有拦截的模型如下:
data(iris)
lmFit <- lm(Sepal.Length ~ 0 + Petal.Length + Petal.Width, data=iris)
> round(coef(lmFit),2)
Petal.Length Petal.Width
2.86 -4.48
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用插入符号匹配相同的模型,则生成的模型包含截取:
library(caret)
caret_lmFit <- train(Sepal.Length~0+Petal.Length+Petal.Width, data=iris, "lm")
> round(coef(caret_lmFit$finalModel),2)
(Intercept) Petal.Length Petal.Width
4.19 0.54 -0.32
Run Code Online (Sandbox Code Playgroud)
如何caret::train排除拦截术语?
我的问题是关系到这一个 关于分类数据使用插入符包时(在R项因素).我从链接的帖子中了解到,如果你使用"公式界面",一些功能可能是因素,培训将正常工作.我的问题是如何使用该preProcess()功能扩展数据?如果我尝试在具有某些列作为因素的数据框上执行此操作,则会收到以下错误消息:
Error in preProcess.default(etitanic, method = c("center", "scale")) :
all columns of x must be numeric
Run Code Online (Sandbox Code Playgroud)
在这里看到一些示例代码:
library(earth)
data(etitanic)
a <- preProcess(etitanic, method=c("center", "scale"))
b <- predict(etitanic, a)
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在使用caret包来调整glmnet逻辑回归模型.虽然lambda最佳曲调的值是我在其中指定tuneGrid的lambda值之一,但最终模型的值完全不同:
require(caret)
set.seed(1)
x <- matrix(runif(1000), nrow = 100)
y <- factor(rbinom(100, 1, 0.5))
lambda.seq <- exp(seq(log(1e-5), log(1e0), length.out = 20))
model <- train(x, y,
method ="glmnet",
family = "binomial",
tuneGrid = expand.grid(alpha = 1,
lambda = lambda.seq))
model$bestTune
# alpha lambda
# 13 1 0.0143845
model$finalModel$lambdaOpt
# [1] 0.0143845
model$finalModel$lambda
# [1] 0.1236344527 0.1126511087 0.1026434947 0.0935249295 0.0852164325 0.0776460395
# [7] 0.0707481794 0.0644631061 0.0587363814 0.0535184032 0.0487639757 0.0444319185
# [13] 0.0404847094 0.0368881594 0.0336111170 …Run Code Online (Sandbox Code Playgroud) 我正在使用多元金融时间序列数据并且在使用该createTimeSlices函数时遇到问题.除了Max Kuhn使用的功能之外,我找不到任何功能.任何人都可以帮助我理解函数的用法吗?