-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
72 lines (52 loc) · 1.9 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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")
```
<br>
`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.