fuzzy_naive_bayes: Fuzzy naive Bayes models for tidymodels

View source: R/tidymodels.R

fuzzy_naive_bayesR Documentation

Fuzzy naive Bayes models for tidymodels

Description

fuzzy_naive_bayes() defines a classification model, estimated by one of the FuzzyClass classifiers, that can be used with the tidymodels ecosystem (parsnip, workflows, recipes, rsample, tune, yardstick, ...).

The classifier is chosen through the engine:

Engine Classifier Main arguments
"gaussian" (default) FuzzyGaussianNaiveBayes() fuzzy
"gamma" FuzzyGammaNaiveBayes() fuzzy
"beta" FuzzyBetaNaiveBayes() fuzzy
"exponential" FuzzyExponentialNaiveBayes() fuzzy
"binomial" FuzzyBinomialNaiveBayes() fuzzy
"poisson" FuzzyPoissonNaiveBayes() fuzzy
"geometric" FuzzyGeoNaiveBayes() fuzzy
"trapezoidal" FuzzyTrapezoidalNaiveBayes() fuzzy
"triangular" FuzzyTriangularNaiveBayes() fuzzy
"hypergeometric" FuzzyHipergeometricNaiveBayes() fuzzy
"bayes_rule" FuzzyBayesRule() fuzzy
"naive" FuzzyNaiveBayes() fuzzy
"dw_gamma" DWFuzzyGammaNaiveBayes() fuzzy
"dw_hypergeometric" DWFuzzyHipergeometricNaiveBayes() fuzzy
"gaussian_fuzzy_param" GauNBFuzzyParam() alpha_cut, ranking_method
"exponential_fuzzy_param" ExpNBFuzzyParam() alpha_cut, ranking_method
"poisson_fuzzy_param" PoiNBFuzzyParam() alpha_cut, ranking_method

Main arguments that do not apply to the chosen engine are ignored. Any other argument of the classifier (e.g. wdelta and weta for the double weighted classifiers, alp and w for ranking_method = 4, or verbose) can be passed through parsnip::set_engine().

The predictors are passed to the classifier as they are (no dummy variables are created), so use a recipe to prepare them when needed. Each fit prints a training message; set options(FuzzyClass.verbose = FALSE) (see fuzzy_verbose()) or set_engine(..., verbose = FALSE) to silence it, for example when tuning.

This function requires the parsnip package.

Usage

fuzzy_naive_bayes(
  mode = "classification",
  engine = "gaussian",
  fuzzy = NULL,
  alpha_cut = NULL,
  ranking_method = NULL
)

## S3 method for class 'fuzzy_naive_bayes'
update(
  object,
  parameters = NULL,
  fuzzy = NULL,
  alpha_cut = NULL,
  ranking_method = NULL,
  fresh = FALSE,
  ...
)

Arguments

mode

A single character string for the type of model. The only possible value is "classification".

engine

A single character string specifying the classifier (see the table above).

fuzzy

Logical; whether the membership functions are used (argument fuzzy of the classifiers). Tunable with fuzzy_membership().

alpha_cut

Smallest alpha-cut of the fuzzy parameters (argument alphacut). Tunable with alpha_cut().

ranking_method

Integer from 1 to 5: method used to rank the fuzzy numbers (argument metd). Tunable with ranking_method().

object

A fuzzy_naive_bayes model specification.

parameters

A 1-row data frame (or NULL) with the new values of the main arguments, as used by tune::finalize_model().

fresh

Logical; replace all the arguments (TRUE) or only update the ones given (FALSE)?

...

Engine-specific arguments to update.

Value

A model specification object with classes fuzzy_naive_bayes and model_spec.

Examples


library(parsnip)

spec <- fuzzy_naive_bayes(fuzzy = TRUE) |>
  set_engine("gaussian")
spec

model_fit <- fit(spec, Species ~ ., data = iris)
predict(model_fit, iris[c(1, 51, 101), ])
predict(model_fit, iris[c(1, 51, 101), ], type = "prob")

# Fuzzy parameters with the GTFN ranking method
fuzzy_naive_bayes(ranking_method = 5) |>
  set_engine("gaussian_fuzzy_param") |>
  fit(Species ~ ., data = iris)

# Engine-specific arguments
data(GamWeightData)
fuzzy_naive_bayes() |>
  set_engine("dw_gamma", wdelta = rep(1/3, 3), weta = c(0.3, 0.2, 0.5)) |>
  fit(class ~ ., data = GamWeightData)


FuzzyClass documentation built on Oct. 22, 2026, 1:07 a.m.