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
- Host: GitHub
- URL: https://github.com/rsquaredacademy/mbar
- Owner: rsquaredacademy
- License: other
- Created: 2019-04-16T07:59:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-10T14:15:30.000Z (over 6 years ago)
- Last Synced: 2025-02-12T11:17:12.241Z (8 months ago)
- Topics: association-rules, market-basket-analysis, rstats
- Language: R
- Homepage: https://www.rsquaredacademy.com
- Size: 82 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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[](https://travis-ci.org/rsquaredacademy/mbar) [](https://ci.appveyor.com/project/rsquaredacademy/mbar) [](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.