Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/smaakage85/modelgrid

A Minimalistic Framework for Creating, Managing and Training Multiple Caret Models
https://github.com/smaakage85/modelgrid

caret machine-learning predictive-analytics predictive-modeling

Last synced: 3 months ago
JSON representation

A Minimalistic Framework for Creating, Managing and Training Multiple Caret Models

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```

# modelgrid

[![Travis-CI Build Status](https://travis-ci.org/smaakage85/modelgrid.svg?branch=master)](https://travis-ci.org/smaakage85/modelgrid)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/smaakage85/modelgrid?branch=master&svg=true)](https://ci.appveyor.com/project/smaakage85/modelgrid)

This is a small package offering a minimalistic but flexible framework for
creating, managing and training multiple caret models with a bare minimum of code.

## Installation

`modelgrid` can be installed from CRAN with `install.packages('modelgrid')`.
If you want the development version then install directly from GitHub:

```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("smaakage85/modelgrid")
```

## Building your first model grid

First, pre-allocate an empty model grid with the constructor function `model_grid`.

```{r, message = FALSE}
library(modelgrid)
mg <- model_grid()

mg
```

As you see, a `model_grid` has three components:

* `shared_settings`: settings to be shared across models. Obvious choices include
the target variable, features and resampling scheme.
* `models`: settings that uniquely identify the indvidual models.
* `model_fits`: contains the fitted models, once the `model_grid` has been trained.

Next, decide what settings you want to be shared by the models constituting the
`model_grid`.

```{r, message = FALSE}
library(dplyr)
library(lattice)
library(caret)
data(GermanCredit)

mg <-
mg %>%
share_settings(
y = GermanCredit[["Class"]],
x = GermanCredit %>% select(-Class),
metric = "ROC",
trControl = trainControl(
method = "cv",
number = 5,
summaryFunction = twoClassSummary,
classProbs = TRUE
)
)
```

Our first model candidate will be a simple Random Forest configuration.

```{r}
mg <-
mg %>%
add_model(
model_name = "Funky Forest",
method = "rf",
tuneLength = 5
)
```

Let us also give an eXtreme Gradient Boosting model a shot.

```{r}
mg <-
mg %>%
add_model(
model_name = "Big Boost",
method = "xgbTree",
nthread = 8
)
```

That's it. We are all set to train our first very own (extremely simple)
model grid.

```{r, message = FALSE}
mg <- train(mg)
```

Visualize performance statistics of final models.

```{r performance_bwplot}
mg$model_fits %>%
resamples(.) %>%
bwplot(.)
```

You want to know more about all of the exciting features of the `model_grid`? Take a look at the vignette (: