rule_based_assessment.Rd
Provides a stats::glm type wrapper around user-defined function specifying rules for a classification function.
rule_based_assessment(formula, data, rules)
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.
a dataframe containing the variables and target of the rule function.
a function implementing the rules-based classification.
an object class similar to "glm" that can be used with a 'predict' method.
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"))
#> [1] "not apple"