Title: | Look-Up Tables using S4 |
---|---|
Description: | Fits look-up tables by filling entries with the mean or median values of observations fall in partitions of the feature space. Partitions can be determined by user of the package using input argument feature.boundaries, and dimensions of the feature space can be any combination of continuous and categorical features provided by the data set. A Predict function directly fetches corresponding entry value, and a default value is defined as the mean or median of all available observations. The table and other components are represented using the S4 class lookupTable. |
Authors: | Enzo Jia [aut, cre], Marc Maier [aut] |
Maintainer: | Enzo Jia <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1 |
Built: | 2024-11-16 04:49:54 UTC |
Source: | https://github.com/enzochia/lookuptable |
Initialize and construct a lookupTable object
## S4 method for signature 'lookupTable' initialize(.Object, df.input, response, feature.boundaries, features.con = character(0), features.cat = character(0), fill.method = "mean")
## S4 method for signature 'lookupTable' initialize(.Object, df.input, response, feature.boundaries, features.con = character(0), features.cat = character(0), fill.method = "mean")
.Object |
the prototype object |
df.input |
training data set containing columns with names found in features.con and features.cat vectors |
response |
name of the response variable |
feature.boundaries |
a list of thresholds for each continuous feature (names contained in feature.con) to construct bins. Should use -Inf and Inf as the first and last values, respectively. |
features.con |
a vector of continuous feature names |
features.cat |
a vector of categorical feature names |
fill.method |
the method to fill entries of the table ('mean' or 'median') |
A lookupTable object with a table trained with df.input data
An S4 class that defines the look-up table and all other components required for prediction using this table.
table
the look-up table with entries to be retrieved as prediction results
feature.con
a vector of continuous feature names
feature.cat
a vector of categorical feature names
feature.boundaries
a list of boundaries for each input feature (inferred during construction from input data)
response
the name of the response variable for the look-up table
default
the default value for cells corresponding to a missing combination of input values
response.categories
sequence of all categories (order-dependent) for the response variable, if it's categorical
predict
method for lookupTable
objects
## S3 method for class 'lookupTable' predict(object, newdata, newparams = NULL, allow.new.levels = FALSE, na.action = na.pass, ...)
## S3 method for class 'lookupTable' predict(object, newdata, newparams = NULL, allow.new.levels = FALSE, na.action = na.pass, ...)
object |
a fitted lookupTable object |
newdata |
data.frame from which to evaluate predictions |
newparams |
new parameters to use in evaluating predictions |
allow.new.levels |
(logical) if FALSE (default), then any new levels
(or NA values) detected in |
na.action |
function determining what should be done with missing values for fixed effects in |
... |
optional additional parameters. None are used at present. |
a numeric vector of predicted values
df.input <- cars response <- 'dist' feature.boundaries <- list(c(-Inf, 5, 10, 15, 20, 25, Inf)) features.con <- c('speed') dist.table <- lookupTable(df.input, response, feature.boundaries, features.con) df.test <- data.frame(speed = c(2, 23, 41, 5, 9, 8)) predict(dist.table, df.test)
df.input <- cars response <- 'dist' feature.boundaries <- list(c(-Inf, 5, 10, 15, 20, 25, Inf)) features.con <- c('speed') dist.table <- lookupTable(df.input, response, feature.boundaries, features.con) df.test <- data.frame(speed = c(2, 23, 41, 5, 9, 8)) predict(dist.table, df.test)