-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathstep_lencode_glm.Rd
114 lines (98 loc) · 4.13 KB
/
step_lencode_glm.Rd
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lencode_glm.R
\name{step_lencode_glm}
\alias{step_lencode_glm}
\alias{tidy.step_lencode_glm}
\title{Supervised Factor Conversions into Linear Functions using Likelihood
Encodings}
\usage{
step_lencode_glm(
recipe,
...,
role = NA,
trained = FALSE,
outcome = NULL,
mapping = NULL,
skip = FALSE,
id = rand_id("lencode_glm")
)
}
\arguments{
\item{recipe}{A recipe object. The step will be added to the sequence of
operations for this recipe.}
\item{...}{One or more selector functions to choose variables. For
\code{step_lencode_glm}, this indicates the variables to be encoded into a
numeric format. See \code{\link[recipes:selections]{recipes::selections()}} for more details. For the
\code{tidy} method, these are not currently used.}
\item{role}{Not used by this step since no new variables are created.}
\item{trained}{A logical to indicate if the quantities for preprocessing have
been estimated.}
\item{outcome}{A call to \code{vars} to specify which variable is used as the
outcome in the generalized linear model. Only numeric and two-level factors
are currently supported.}
\item{mapping}{A list of tibble results that define the encoding. This is
\code{NULL} until the step is trained by \code{\link[recipes:prep]{recipes::prep()}}.}
\item{skip}{A logical. Should the step be skipped when the recipe is baked by
\code{\link[recipes:bake]{recipes::bake()}}? While all operations are baked when \code{\link[recipes:prep]{recipes::prep()}} is
run, some operations may not be able to be conducted on new data (e.g.
processing the outcome variable(s)). Care should be taken when using \code{skip = TRUE} as it may affect the computations for subsequent operations}
\item{id}{A character string that is unique to this step to identify it.}
}
\value{
An updated version of \code{recipe} with the new step added to the
sequence of existing steps (if any). For the \code{tidy} method, a tibble with
columns \code{terms} (the selectors or variables for encoding), \code{level} (the
factor levels), and \code{value} (the encodings).
}
\description{
\code{step_lencode_glm()} creates a \emph{specification} of a recipe step that will
convert a nominal (i.e. factor) predictor into a single set of scores derived
from a generalized linear model.
}
\details{
For each factor predictor, a generalized linear model is fit to the outcome
and the coefficients are returned as the encoding. These coefficients are on
the linear predictor scale so, for factor outcomes, they are in log-odds
units. The coefficients are created using a no intercept model and, when two
factor outcomes are used, the log-odds reflect the event of interest being
the \emph{first} level of the factor.
For novel levels, a slightly timmed average of the coefficients is returned.
}
\section{Tidying}{
When you \code{\link[recipes:tidy.recipe]{tidy()}} this step, a tibble is returned with
columns \code{level}, \code{value}, \code{terms}, and \code{id}:
\describe{
\item{level}{character, the factor levels}
\item{value}{numeric, the encoding}
\item{terms}{character, the selectors or variables selected}
\item{id}{character, id of this step}
}
}
\section{Case weights}{
This step performs an supervised operation that can utilize case weights.
To use them, see the documentation in \link[recipes:case_weights]{recipes::case_weights} and the examples on
\code{tidymodels.org}.
}
\examples{
\dontshow{if (rlang::is_installed("modeldata")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
library(recipes)
library(dplyr)
library(modeldata)
data(grants)
set.seed(1)
grants_other <- sample_n(grants_other, 500)
\donttest{
reencoded <- recipe(class ~ sponsor_code, data = grants_other) \%>\%
step_lencode_glm(sponsor_code, outcome = vars(class))
}
\dontshow{\}) # examplesIf}
}
\references{
Micci-Barreca D (2001) "A preprocessing scheme for high-cardinality
categorical attributes in classification and prediction problems," ACM SIGKDD
Explorations Newsletter, 3(1), 27-32.
Zumel N and Mount J (2017) "vtreat: a data.frame Processor for Predictive
Modeling," arXiv:1611.09477
}
\concept{preprocessing encoding}
\keyword{datagen}