Description Usage Arguments See Also Examples
Mungebits are atomic data transformations of a data.frame that, loosely speaking, aim to modify "one thing" about a variable or collection of variables. This is pretty loosely defined, but examples include dropping variables, mapping values, discretization, etc.
Imagine flipping a switch on a set of train tracks. A mungebit
behaves like this: once the trained
switch is flipped,
it can only run the predict_fn
, otherwise it will
run the train_fn
.
Run the predict function on a mungebit.
Run the train function on a mungebit.
1 2 3 4 5 6 7 8 | mungebit__initialize(train_fn = function(x) x, predict_fn = train_fn,
enforce_train = TRUE)
mungebit__run(mungeplane, ...)
mungebit__predict(mungeplane, ...)
mungebit__train(mungeplane, ...)
|
train_fn |
function. This specifies the behavior to perform on the dataset when preparing for model training. A value of NULL specifies that there should be no training step. |
predict_fn |
function. This specifies the behavior to perform on the dataset when preparing for model prediction. A value of NULL specifies that there should be no prediction step. |
enforce_train |
logical. Whether or not to flitch the trained flag during runtime. |
mungeplane |
mungeplane. Essentially an environment containing
a |
... |
additional arguments to the mungebit's |
mungebit__run
, mungebit__initialize
mungebit__run
, mungebit__initialize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Not run:
mp <- mungeplane(iris)
mb <- mungebit(column_transformation(function(col, scale = NULL) {
if ('scale' %in% names(inputs))
cat("Column scaled by ", inputs$scale, "\n")
else inputs$scale <<- scale
col * inputs$scale
}))
mb$run(mp, 'Sepal.Length', 2)
# mp$data now contains a copy of iris w/ the Sepal.Length column doubled
head(mp$data[[1]] / iris[[1]])
# > [1] 2 2 2 2 2 2
mb$run(mp, 'Sepal.Length')
# > Column scaled by 2
head(mp$data[[1]] / iris[[1]])
# > [1] 4 4 4 4 4 4
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.