Package 'lookupTable'

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

Help Index


Initialize and construct a lookupTable object

Description

Initialize and construct a lookupTable object

Usage

## S4 method for signature 'lookupTable'
initialize(.Object, df.input, response,
  feature.boundaries, features.con = character(0),
  features.cat = character(0), fill.method = "mean")

Arguments

.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')

Value

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.

Description

An S4 class that defines the look-up table and all other components required for prediction using this table.

Slots

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


Predictions from a look-up table

Description

predict method for lookupTable objects

Usage

## S3 method for class 'lookupTable'
predict(object, newdata, newparams = NULL,
  allow.new.levels = FALSE, na.action = na.pass, ...)

Arguments

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 newdata will trigger an error; if TRUE, then the prediction will use the unconditional (population-level) values for data with previously unobserved levels (or NAs)

na.action

function determining what should be done with missing values for fixed effects in newdata. The default is to predict NA: see na.pass.

...

optional additional parameters. None are used at present.

Value

a numeric vector of predicted values

Examples

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)