Skip to content

Commit

Permalink
kable-didnt-work
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmayer committed Aug 13, 2024
1 parent bc4571a commit 87dc2de
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ print(summary(models))
#> The following models were ensembled: rf, glmnet
#>
#> Model accuracy:
#> model_name metric value sd
#> <char> <char> <num> <num>
#> 1: rf RMSE 1065.605 145.4863
#> 2: glmnet RMSE 1206.800 175.7538
#> model_name metric value sd
#> <char> <char> <num> <num>
#> 1: rf RMSE 960.6879 185.7793
#> 2: glmnet RMSE 1129.2088 141.2402
```

Then, use caretEnsemble to make a greedy ensemble of these models
Expand All @@ -67,18 +67,18 @@ print(greedy_stack)
#> Summary of sample sizes: 400, 400, 400, 400, 400
#> Resampling results:
#>
#> RMSE Rsquared MAE
#> 1043.649 0.92586 543.4189
#> RMSE Rsquared MAE
#> 935.4086 0.9478161 527.013
#>
#> Tuning parameter 'max_iter' was held constant at a value of 100
#>
#> Final model:
#> Greedy MSE
#> RMSE: 1044.709
#> RMSE: 933.8605
#> Weights:
#> [,1]
#> rf 0.72
#> glmnet 0.28
#> rf 0.7
#> glmnet 0.3
ggplot2::autoplot(greedy_stack, training_data = dat, xvars = c("carat", "table"))
```

Expand All @@ -100,8 +100,8 @@ print(rf_stack)
#> Summary of sample sizes: 400, 400, 400, 400, 400
#> Resampling results:
#>
#> RMSE Rsquared MAE
#> 1049.47 0.9219408 522.2029
#> RMSE Rsquared MAE
#> 849.1342 0.9573736 456.2256
#>
#> Tuning parameter 'mtry' was held constant at a value of 2
#>
Expand All @@ -113,8 +113,8 @@ print(rf_stack)
#> Number of trees: 500
#> No. of variables tried at each split: 2
#>
#> Mean of squared residuals: 1188152
#> % Var explained: 91.49
#> Mean of squared residuals: 669531.3
#> % Var explained: 95.8
ggplot2::autoplot(rf_stack, training_data = dat, xvars = c("carat", "table"))
```

Expand Down
6 changes: 0 additions & 6 deletions README.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ knitr::opts_chunk$set(
fig.path = "man/figures/README-",
out.width = "100%"
)
knitr::opts_chunk$set(render = function(x, options) {
if (is.data.frame(x) || is.matrix(x)) {
return(knitr::kable(x))
}
knitr::knit_print(x)
})
```

# caretEnsemble
Expand Down
Binary file modified man/figures/README-unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions vignettes/Version-4.0-New-Features.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ knitr::opts_chunk$set(
warning = FALSE,
message = FALSE
)
knitr::opts_chunk$set(render = function(x, options) {
if (is.data.frame(x) || is.matrix(x)) {
return(knitr::kable(x))
}
knitr::knit_print(x)
})
set.seed(42L)
```

Expand Down
11 changes: 3 additions & 8 deletions vignettes/caretEnsemble-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ knitr::opts_chunk$set(
warning = FALSE,
message = FALSE
)
knitr::opts_chunk$set(render = function(x, options) {
if (is.data.frame(x) || is.matrix(x)) {
return(knitr::kable(x))
}
knitr::knit_print(x)
})
```

`caretEnsemble` is a package for making ensembles of caret models. You should already be somewhat familiar with the caret package before trying out `caretEnsemble`.
Expand All @@ -34,22 +28,23 @@ knitr::opts_chunk$set(render = function(x, options) {
`caretList` is a flexible function for fitting many different caret models, with the same resampling parameters, to the same dataset. It returns a convenient `list` of caret objects which can later be passed to `caretEnsemble` and `caretStack`. `caretList` has almost exactly the same arguments as `train` (from the caret package), with the exception that the `trControl` argument comes last. It can handle both the formula interface and the explicit `x`, `y` interface to train. As in caret, the formula interface introduces some overhead and the `x`, `y` interface is preferred.

`caretEnsemble` has 2 arguments that can be used to specify which models to fit: `methodList` and `tuneList`. `methodList` is a simple character vector of methods that will be fit with the default `train` parameters, while `tuneList` can be used to customize the call to each component model and will be discussed in more detail later. First, lets build an example dataset (adapted from the caret vignette):
```{r, results="hide"}
```{r}
data(Sonar, package = "mlbench")
set.seed(107L)
inTrain <- caret::createDataPartition(y = Sonar$Class, p = 0.75, list = FALSE)
training <- Sonar[inTrain, ]
testing <- Sonar[-inTrain, ]
```

```{r, echo=TRUE, results="hide", warning=FALSE}
```{r}
model_list <- caretEnsemble::caretList(
Class ~ .,
data = training,
methodList = c("glmnet", "rpart")
)
print(summary(model_list))
```

(As with `train`, the formula interface is convenient but introduces move overhead. For large datasets the explicitly passing `x` and `y` is preferred).
We can use the `predict` function to extract predictions from this object for new data:
```{r}
Expand Down

0 comments on commit 87dc2de

Please sign in to comment.