FuzzyClassifier: Base R6 class of the FuzzyClass classifiers

FuzzyClassifierR Documentation

Base R6 class of the FuzzyClass classifiers

Description

FuzzyClassifier is the (abstract) R6 class shared by every classifier of the package. It implements the common workflow:

  • ⁠$new(...)⁠ creates an untrained model holding its hyperparameters;

  • ⁠$fit(train, cl)⁠ estimates the model and reports the progress;

  • ⁠$predict(newdata, type)⁠ classifies new observations;

  • ⁠$set_params(...)⁠ changes hyperparameters (the model must be re-trained).

Do not instantiate it directly: use one of the concrete classes, e.g. FuzzyGaussianNaiveBayesModel, FuzzyGammaNaiveBayesModel or GauNBFuzzyParamModel. Each of them also has a functional interface (e.g. FuzzyGaussianNaiveBayes()) that trains and returns the R6 object, and every classifier is available to tidymodels through fuzzy_naive_bayes().

Since ⁠$fit()⁠ and ⁠$set_params()⁠ return the object invisibly, calls can be chained: FuzzyGammaNaiveBayesModel$new()$fit(x, y)$predict(x_new).

Public fields

params

Named list with the hyperparameters of the classifier.

estimates

List with the quantities estimated by ⁠$fit()⁠ (NULL while the model has not been trained).

predictors

Names of the predictors seen during training.

classes

Classes (levels of the response) seen during training.

n_obs

Number of training observations.

fit_time

Training time, in seconds.

Active bindings

label

Name of the classifier (read-only); it depends on whether the membership functions are used (fuzzy).

Methods

Public methods


FuzzyClassifier$new()

Create a new (untrained) classifier.

Usage
FuzzyClassifier$new(...)
Arguments
...

Named hyperparameters of the classifier.


FuzzyClassifier$fit()

Estimate the classifier from training data.

Usage
FuzzyClassifier$fit(train, cl, verbose = fuzzy_verbose())
Arguments
train

Matrix or data frame of training set cases.

cl

Factor (or vector) of true classifications of the training set.

verbose

Logical; if TRUE (default, see fuzzy_verbose()) a message reports the training progress.

Returns

The trained object, invisibly.


FuzzyClassifier$predict()

Classify new observations.

Usage
FuzzyClassifier$predict(newdata, type = c("class", "prob", "matrix", "raw"))
Arguments
newdata

Matrix or data frame of test set cases, with the predictors in the same order used in training.

type

"class" (default) for a factor of predicted classes, or "prob" for a matrix of class probabilities (one column per class). "matrix" and "raw" are accepted as synonyms of "prob".

Returns

A factor (type = "class") or a numeric matrix.


FuzzyClassifier$set_params()

Update hyperparameters. The model is reset and must be trained again with ⁠$fit()⁠.

Usage
FuzzyClassifier$set_params(...)
Arguments
...

Named hyperparameters, as in ⁠$new()⁠.

Returns

The object, invisibly.


FuzzyClassifier$is_fitted()

Has the model been trained?

Usage
FuzzyClassifier$is_fitted()
Returns

TRUE or FALSE.


FuzzyClassifier$print()

Print a summary of the classifier.

Usage
FuzzyClassifier$print(...)
Arguments
...

Ignored.


FuzzyClassifier$clone()

The objects of this class are cloneable with this method.

Usage
FuzzyClassifier$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

model <- FuzzyGaussianNaiveBayesModel$new(fuzzy = TRUE)
model$fit(train = iris[, -5], cl = iris$Species)
model

head(model$predict(iris[, -5]))
head(model$predict(iris[, -5], type = "prob"))

# S3 generics also work
head(predict(model, iris[, -5]))

# Change a hyperparameter and re-train, silently
model$set_params(fuzzy = FALSE)$fit(iris[, -5], iris$Species, verbose = FALSE)
model$label

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