|
1 | 1 |
|
2 | 2 | <!-- README.md is generated from README.Rmd. Please edit that file -->
|
3 | 3 |
|
4 |
| -[](https://travis-ci.org/Quantargo/bmarketing) |
6 |
| -[](https://codecov.io/github/Quantargo/bmarketing?branch=master) |
8 |
| - |
9 | 4 | ## Overview
|
10 | 5 |
|
11 |
| -The bmarketing |
12 |
| -dataset |
| 6 | +This package offers a series of functions that will clean, transform and |
| 7 | +build a decision tree model for your input dataset. The functions are |
| 8 | +split in different R scripts inside the R folder and should be executed |
| 9 | +as explained below. |
| 10 | + |
| 11 | +## Function Description |
| 12 | + |
| 13 | +clean\_data : This function will check if the target variable contains |
| 14 | +missing calues and returns an error. It also gives warnings if other |
| 15 | +variables contain NAs and removes thoe columns that have more than 50% |
| 16 | +NAs. |
| 17 | + |
| 18 | +transform\_data : Data transformation step transforms the numeric |
| 19 | +variables using log and transforms factors into numeric variables (and |
| 20 | +vice versa). |
| 21 | + |
| 22 | +model\_data : This function builds a decision tree for the provided |
| 23 | +dataset. |
| 24 | + |
| 25 | +model\_plot : Plots the decision tree created in the precious step. |
| 26 | + |
| 27 | +model\_predict: Returns the predicted classes from the decision tree. |
| 28 | + |
| 29 | +model\_performance : This functions calculated the accuracy of the |
| 30 | +model. |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +Here is how to use the package |
| 35 | + |
| 36 | +``` r |
| 37 | +library(bmarketing) |
| 38 | +df <- import_data_from_csv("~/CloudStation/Projekte/r_projects/bmarketing2.csv") |
| 39 | +#> Warning: Missing column names filled in: 'X1' [1] |
| 40 | +##clean_data(df, target_var = "Y") |
| 41 | + |
| 42 | +df[is.na(df$Y), "Y"] <- 0 |
| 43 | +df <- clean_data(df, target_var = "Y") |
| 44 | +#> Warning in clean_data(df, target_var = "Y"): Column(s) HOUSING, POUTCOME, |
| 45 | +#> MONTH have too many NAs and will be excluded |
| 46 | + |
| 47 | +df <- transform_data(df, c("AGE", "DURATION")) |
| 48 | + |
| 49 | +target_var <- "Y" |
| 50 | +m <- model_data(df, target_var) |
| 51 | + |
| 52 | +model_plot(m) |
| 53 | +``` |
| 54 | + |
| 55 | +<!-- --> |
| 56 | + |
| 57 | +``` r |
| 58 | + |
| 59 | +target <- df[, target_var][[1]] |
| 60 | +predictions <- model_predict(m, df) |
| 61 | + |
13 | 62 |
|
14 |
| -<!-- TODO: Change README to make it more descriptive, add examples, etc. --> |
| 63 | +model_performance(target, predictions) |
| 64 | +#> $accuracy |
| 65 | +#> [1] 0.8131207 |
| 66 | +#> |
| 67 | +#> $sensitivity |
| 68 | +#> [1] NaN |
| 69 | +#> |
| 70 | +#> $specificity |
| 71 | +#> [1] 0.8499763 |
| 72 | +``` |
0 commit comments