1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/relu.R
3\name{step_relu}
4\alias{step_relu}
5\title{Apply (Smoothed) Rectified Linear Transformation}
6\usage{
7step_relu(
8  recipe,
9  ...,
10  role = "predictor",
11  trained = FALSE,
12  shift = 0,
13  reverse = FALSE,
14  smooth = FALSE,
15  prefix = "right_relu_",
16  columns = NULL,
17  skip = FALSE,
18  id = rand_id("relu")
19)
20}
21\arguments{
22\item{recipe}{A recipe object. The step will be added to the
23sequence of operations for this recipe.}
24
25\item{...}{One or more selector functions to choose variables
26for this step. See \code{\link[=selections]{selections()}} for more details.}
27
28\item{role}{For model terms created by this step, what analysis role should
29they be assigned? By default, the new columns created by this step from
30the original variables will be used as \emph{predictors} in a model.}
31
32\item{trained}{A logical to indicate if the quantities for
33preprocessing have been estimated.}
34
35\item{shift}{A numeric value dictating a translation to apply to the data.}
36
37\item{reverse}{A logical to indicate if the left hinge should be used as
38opposed to the right hinge.}
39
40\item{smooth}{A logical indicating if the softplus function, a smooth
41approximation to the rectified linear transformation, should be used.}
42
43\item{prefix}{A prefix for generated column names, defaults to "right_relu_"
44for right hinge transformation and "left_relu_" for reversed/left hinge
45transformations.}
46
47\item{columns}{A character string of variable names that will
48be populated (eventually) by the \code{terms} argument.}
49
50\item{skip}{A logical. Should the step be skipped when the
51recipe is baked by \code{\link[=bake.recipe]{bake.recipe()}}? While all operations are baked
52when \code{\link[=prep.recipe]{prep.recipe()}} is run, some operations may not be able to be
53conducted on new data (e.g. processing the outcome variable(s)).
54Care should be taken when using \code{skip = TRUE} as it may affect
55the computations for subsequent operations.}
56
57\item{id}{A character string that is unique to this step to identify it.}
58}
59\value{
60An updated version of \code{recipe} with the new step added to the
61sequence of any existing operations.
62}
63\description{
64\code{step_relu} creates a \emph{specification} of a recipe step that
65will apply the rectified linear or softplus transformations to numeric
66data. The transformed data is added as new columns to the data matrix.
67}
68\details{
69The rectified linear transformation is calculated as
70\deqn{max(0, x - c)} and is also known as the ReLu or right hinge function.
71If \code{reverse} is true, then the transformation is reflected about the
72y-axis, like so: \deqn{max(0, c - x)} Setting the \code{smooth} option
73to true will instead calculate a smooth approximation to ReLu
74according to \deqn{ln(1 + e^(x - c)} The \code{reverse} argument may
75also be applied to this transformation.
76}
77\section{Connection to MARS}{
78
79
80The rectified linear transformation is used in Multivariate Adaptive
81Regression Splines as a basis function to fit piecewise linear functions to
82data in a strategy similar to that employed in tree based models. The
83transformation is a popular choice as an activation function in many
84neural networks, which could then be seen as a stacked generalization of
85MARS when making use of ReLu activations. The hinge function also appears
86in the loss function of Support Vector Machines, where it penalizes
87residuals only if they are within a certain margin of the decision boundary.
88}
89
90\examples{
91library(modeldata)
92data(biomass)
93
94biomass_tr <- biomass[biomass$dataset == "Training",]
95biomass_te <- biomass[biomass$dataset == "Testing",]
96
97rec <- recipe(HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
98              data = biomass_tr)
99
100transformed_te <- rec \%>\%
101  step_relu(carbon, shift = 40) \%>\%
102  prep(biomass_tr) \%>\%
103  bake(biomass_te)
104
105transformed_te
106}
107\seealso{
108Other individual transformation steps:
109\code{\link{step_BoxCox}()},
110\code{\link{step_YeoJohnson}()},
111\code{\link{step_bs}()},
112\code{\link{step_harmonic}()},
113\code{\link{step_hyperbolic}()},
114\code{\link{step_inverse}()},
115\code{\link{step_invlogit}()},
116\code{\link{step_logit}()},
117\code{\link{step_log}()},
118\code{\link{step_mutate}()},
119\code{\link{step_ns}()},
120\code{\link{step_poly}()},
121\code{\link{step_sqrt}()}
122}
123\concept{individual transformation steps}
124