How to caret predict ntiles of rqlasso?
tried:
Control <- caret::trainControl(method = "cv",number = 5)
myModel <- caret::train(myFormula, df_train,trCtrl= Control,method = "rqlasso",tuneLength=10)
preds <- predict(myModel, df_test) # , type = "raw"
... but get no quantile/ntiles estimates. Do I need a tau-definition here?
Thank you reader/writer.
Hard to say without this. Need a reprex
. See the FAQ.
Complete Example:
`
suppressPackageStartupMessages(library(caret))
suppressPackageStartupMessages(library(quantreq))
df <- matrix(rnorm(1000), ncol = 2) %>%
as.data.frame() %>%
dplyr::mutate(y = sample(1000/2))
colnames(df)<-c('one','two','y')
rownames(df) <- NULL
df <- df %>% dplyr::mutate(id=row_number())
myLimit <- base::max(df[['id']])
myLimit <- myLimit-30
df_train <- df %>% filter(id <= myLimit)
df_test <- df %>% filter(id > myLimit)
allData <- dplyr::bind_rows(df_train,df_test)
myFormula <- paste0('y ~ one + two')
myFormula <- as.formula(myFormula)
Control <- caret::trainControl(method = "cv",number = 5)
myModel <- caret::train(myFormula, df_train,trCtrl= Control,method = "rqlasso",tuneLength=10)
preds <- predict(myModel, df_test) # , type = "raw"
print('preds')
print(as_tibble(preds),n=20,max_extra_cols=0,width=110)`
output (no quantile preds):
[1] "preds"
# A tibble: 30 x 1
value
<dbl>
1 250
2 250
3 250
4 250
5 250
6 250
7 250
8 250
output standalone-algo 'quantreg' :
myModel <- quantreg::rq(myFormula,data=df_train,tau=seq(0.1, 0.9, by = 0.1))
preds <- stats::predict(myModel,newdata=df_test)
print('preds')
print(as_tibble(preds),n=20,max_extra_cols=0,width=110)
[1] "preds"
# A tibble: 30 x 9
`tau= 0.1` `tau= 0.2` `tau= 0.3` `tau= 0.4` `tau= 0.5` `tau= 0.6` `tau= 0.7` `tau= 0.8` `tau= 0.9`
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 44.8 102. 163. 204. 256. 289. 331. 393. 439.
2 33.4 76.4 150. 193. 239. 299. 340. 380. 435.
3 52.5 84.1 143. 195. 249. 315. 361. 406. 456.
4 57.7 111. 162. 207. 265. 296. 342. 409. 452.
5 60.1 117. 166. 209. 270. 293. 339. 412. 453.
6 49.4 102.
system
Closed
4
This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.