Nothing
#' @title Transform pipeline
#' @description A [daltoolbox::dal_transform()] that chains a sequence of transforms. `fit()` fits
#' each step on the output of the previous one, and `transform()` applies the fitted steps in order.
#' It lets a model take its preprocessing as a configurable list of transforms instead of a fixed
#' one-hot-plus-normalization.
#' @param steps A list of `dal_transform` objects (unfitted prototypes), applied in order.
#' @return A `trans_pipeline` object.
#' @examples
#' library(daltoolbox)
#' pipe <- trans_pipeline(list(one_hot(), zscore()))
#' pipe <- fit(pipe, iris)
#' head(transform(pipe, iris))
#' @import daltoolbox
#' @export
trans_pipeline <- function(steps) {
obj <- dal_transform()
obj$steps <- steps
obj$fitted <- NULL
class(obj) <- append("trans_pipeline", class(obj))
obj
}
#' @export
fit.trans_pipeline <- function(obj, data, ...) {
fitted <- vector("list", length(obj$steps))
current <- data
for (i in seq_along(obj$steps)) {
fitted[[i]] <- fit(obj$steps[[i]], current)
current <- transform(fitted[[i]], current)
}
obj$fitted <- fitted
obj
}
#' @export
transform.trans_pipeline <- function(obj, data, ...) {
steps <- if (!is.null(obj$fitted)) obj$fitted else obj$steps
current <- data
for (step in steps) current <- transform(step, current)
current
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.