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

https://github.com/rsquaredacademy/mbar

Miscellaneous functions used in our online R courses
https://github.com/rsquaredacademy/mbar

association-rules market-basket-analysis rstats

Last synced: 6 months ago
JSON representation

Miscellaneous functions used in our online R courses

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mbar

[![Travis build status](https://travis-ci.org/rsquaredacademy/mbar.svg?branch=master)](https://travis-ci.org/rsquaredacademy/mbar) [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/rsquaredacademy/mbar?branch=master&svg=true)](https://ci.appveyor.com/project/rsquaredacademy/mbar) [![Coverage status](https://codecov.io/gh/rsquaredacademy/mbar/branch/master/graph/badge.svg)](https://codecov.io/github/rsquaredacademy/mbar?branch=master)

> Helper functions used in our online R courses

## Installation

```{r installation, eval = FALSE}
# Install development version from GitHub
# install.packages("devtools")
devtools::install_github("rsquaredacademy/mbar")
```

## Usage

### Data pre-processing for Market Basket Analysis

```{r load, eval=TRUE, echo=FALSE}
library(mbar)
```

```{r demo, fig.align='center', echo=FALSE}
knitr::include_graphics("mba_pre_process.png")
```


`mbar_prep_data()` will modify the data from one row per item to
one row per transaction. It takes 3 inputs:

- data set
- invoice number column
- product/item column

```{r usage}
# original data
head(mba_sample)

# modified data
mbar_prep_data(mba_sample, InvoiceNo, Description)
```

### Optimal Complexity Parameter

`optimal_cp()` will extract the optimal complexity parameter from an object
of class `rpart` for pruning a tree.

```{r optimcp}
# grow tree
model <- rpart::rpart(Species ~ ., data = iris)
best_cp <- optimal_cp(model)

# prune tree
rpart::prune(model, cp = best_cp)
```

Please note that the 'mbar' project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.