Skip to content

Commit

Permalink
print
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmayer committed Aug 13, 2024
1 parent e9ae189 commit 4461510
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ models <- caretEnsemble::caretList(
data = dat,
methodList = c("rf", "glmnet")
)
print(summary(models))
#> The following models were ensembled: rf, glmnet
#>
#> Model accuracy:
#> model_name metric value sd
#> <char> <char> <num> <num>
#> 1: rf RMSE 1007.595 192.05082
#> 2: glmnet RMSE 1217.374 69.54145
```

Then, use caretEnsemble to make a greedy ensemble of these models
Expand All @@ -59,18 +67,18 @@ print(greedy_stack)
#> Summary of sample sizes: 400, 400, 400, 400, 400
#> Resampling results:
#>
#> RMSE Rsquared MAE
#> 1034.614 0.9347528 517.897
#> RMSE Rsquared MAE
#> 951.4063 0.947765 545.1398
#>
#> Tuning parameter 'max_iter' was held constant at a value of 100
#>
#> Final model:
#> Greedy MSE
#> RMSE: 1047.523
#> RMSE: 959.2989
#> Weights:
#> [,1]
#> rf 0.78
#> glmnet 0.22
#> rf 0.68
#> glmnet 0.32
ggplot2::autoplot(greedy_stack, training_data = dat, xvars = c("carat", "table"))
```

Expand All @@ -93,7 +101,7 @@ print(rf_stack)
#> Resampling results:
#>
#> RMSE Rsquared MAE
#> 1107.429 0.9264549 532.1966
#> 1030.494 0.9376481 541.5582
#>
#> Tuning parameter 'mtry' was held constant at a value of 2
#>
Expand All @@ -105,8 +113,8 @@ print(rf_stack)
#> Number of trees: 500
#> No. of variables tried at each split: 2
#>
#> Mean of squared residuals: 1293471
#> % Var explained: 92.1
#> Mean of squared residuals: 985743.6
#> % Var explained: 93.99
ggplot2::autoplot(rf_stack, training_data = dat, xvars = c("carat", "table"))
```

Expand Down
1 change: 1 addition & 0 deletions README.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ models <- caretEnsemble::caretList(
data = dat,
methodList = c("rf", "glmnet")
)
print(summary(models))
```

Then, use caretEnsemble to make a greedy ensemble of these models
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: 3 additions & 3 deletions vignettes/Version-4.0-New-Features.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ model_list <- caretEnsemble::caretList(
y = iris[, 5L],
methodList = c("rpart", "rf")
)
summary(model_list)
print(summary(model_list))
```

# Greedy Optimizer in caretEnsemble
The new version uses a greedy optimizer by default, ensuring the ensemble is never worse than the worst single model:
```{r}
ens <- caretEnsemble::caretEnsemble(model_list)
summary(ens)
print(summary(ens))
```

# Enhanced S3 Methods
caretStack (and by extension, caretEnsemble) now supports various S3 methods:
```{r}
print(ens)
summary(ens)
print(summary(ens))
plot(ens)
ggplot2::autoplot(ens)
```
Expand Down
6 changes: 3 additions & 3 deletions vignettes/caretEnsemble-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ model_list <- caretEnsemble::caretList(
data = training,
methodList = c("glmnet", "rpart")
)
summary(model_list)
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:
Expand All @@ -63,7 +63,7 @@ model_list_big <- caretEnsemble::caretList(
nn = caretEnsemble::caretModelSpec(method = "nnet", tuneLength = 2L, trace = FALSE)
)
)
summary(model_list_big)
print(summary(model_list_big))
```

Finally, you should note that `caretList` does not support custom caret models. Fitting those models are beyond the scope of this vignette, but if you do so, you can manually add them to the model list (e.g. `model_list_big[["my_custom_model"]] <- my_custom_model`). Just be sure to use the same re-sampling indexes in `trControl` as you use in the `caretList` models!
Expand All @@ -84,7 +84,7 @@ caret::modelCor(caret::resamples(model_list))
These 2 models make a good candidate for an ensemble: their predictions are fairly uncorrelated, but their overall accuracy is similar. We do a simple, linear greedy optimization on AUC using caretEnsemble:
```{r}
greedy_ensemble <- caretEnsemble::caretEnsemble(model_list)
summary(greedy_ensemble)
print(summary(greedy_ensemble))
```

```{r}
Expand Down

0 comments on commit 4461510

Please sign in to comment.