rule_based_assessment: A rule-based model.

View source: R/rule_based_assessment.R

rule_based_assessmentR Documentation

A rule-based model.

Description

Provides a stats::glm type wrapper around user-defined function specifying rules for a classification function.

Usage

rule_based_assessment(formula, data, rules)

Arguments

formula

an object of class stats::formula, should specify the target and all predictors used in the rule function as a linear combination, e.g. target ~ rule1 + rule2.

data

a dataframe containing the variables and target of the rule function.

rules

a function implementing the rules-based classification.

Value

an object class similar to "glm" that can be used with a 'predict' method.

Examples


d <- data.frame(
  y=c("apple", "apple", "not apple", "not apple"),
  shape=c("round", "round", "square", "round"),
  colour=c("green", "red", "green", "purple")
)

f <- function(shape, colour) {
  ifelse(shape == "round" & colour %in% c("green", "red"), "apple", "not apple")
}

apple_classifier <- rule_based_assessment(y ~ shape + colour, d, f)

predict(apple_classifier, newdata=data.frame(shape="round", colour="indigo"))


barnabywalker/tidyassessments documentation built on April 8, 2022, 12:32 p.m.