| Title: | Fuzzy and Non-Fuzzy Classifiers |
|---|---|
| Description: | It provides classifiers which can be used for discrete variables and for continuous variables based on the Naive Bayes and Fuzzy Naive Bayes hypothesis. Those methods were developed by researchers belong to the 'Laboratory of Technologies for Virtual Teaching and Statistics (LabTEVE)' and 'Laboratory of Applied Statistics to Image Processing and Geoprocessing (LEAPIG)' at 'Federal University of Paraiba, Brazil'. They considered some statistical distributions and their papers were published in the scientific literature, as for instance, the Gaussian classifier using fuzzy parameters, proposed by 'Moraes, Ferreira and Machado' (2021) <doi:10.1007/s40815-020-00936-4>. The classifiers are implemented as 'R6' classes and are also available as 'parsnip' models, so they can be used within the 'tidymodels' framework. |
| Authors: | Jodavid Ferreira [aut, cre] (ORCID: <https://orcid.org/0000-0002-2131-6464>), Ronei Moraes [ctb] (ORCID: <https://orcid.org/0000-0001-8436-8950>), Liliane Machado [ctb] (ORCID: <https://orcid.org/0000-0002-1182-2929>), Arthur Ricardo [ctb], Isaac Araújo [ctb] |
| Maintainer: | Jodavid Ferreira <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-11-20 14:07:17 UTC |
| Source: | https://github.com/leapigufpb/fuzzyclass |
DWFuzzyGammaNaiveBayes Double Weighted Fuzzy Gamma Naive Bayes
DWFuzzyGammaNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, wdelta, weta, verbose = fuzzy_verbose() )DWFuzzyGammaNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, wdelta, weta, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
wdelta |
vector weight each class |
weta |
vector weight each feature |
verbose |
logical; if |
A trained DWFuzzyGammaNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Soares EAMG, Machado LS (2020). “A double weighted fuzzy gamma naive bayes classifier.” Journal of Intelligent & Fuzzy Systems, 38(1), 577–588.
DWFuzzyGammaNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "dw_gamma") for the tidymodels interface.
set.seed(1) # determining a seed data(GamWeightData) # Splitting into Training and Testing split <- caTools::sample.split(t(GamWeightData[, 1]), SplitRatio = 0.7) Train <- subset(GamWeightData, split == "TRUE") Test <- subset(GamWeightData, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- DWFuzzyGammaNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2, wdelta = c(2.002/6,1.998/6,2.000/6), weta = c(3/10,2/10, 5/10) ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])set.seed(1) # determining a seed data(GamWeightData) # Splitting into Training and Testing split <- caTools::sample.split(t(GamWeightData[, 1]), SplitRatio = 0.7) Train <- subset(GamWeightData, split == "TRUE") Test <- subset(GamWeightData, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- DWFuzzyGammaNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2, wdelta = c(2.002/6,1.998/6,2.000/6), weta = c(3/10,2/10, 5/10) ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])
R6 implementation of the Double Weighted Fuzzy Gamma Naive Bayes classifier. Create the model with
DWFuzzyGammaNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
DWFuzzyGammaNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> DWFuzzyGammaNaiveBayes
DWFuzzyGammaNaiveBayes$new()Create a new (untrained) classifier.
DWFuzzyGammaNaiveBayes$new(fuzzy = TRUE, wdelta, weta)
fuzzywdeltawetaDWFuzzyGammaNaiveBayes$clone()The objects of this class are cloneable with this method.
DWFuzzyGammaNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- DWFuzzyGammaNaiveBayesModel$new(wdelta = rep(1/3, 3), weta = c(0.3, 0.2, 0.5)) data(GamWeightData) model$fit(train = GamWeightData[, -4], cl = GamWeightData[, 4]) head(model$predict(GamWeightData[, -4])) modelmodel <- DWFuzzyGammaNaiveBayesModel$new(wdelta = rep(1/3, 3), weta = c(0.3, 0.2, 0.5)) data(GamWeightData) model$fit(train = GamWeightData[, -4], cl = GamWeightData[, 4]) head(model$predict(GamWeightData[, -4])) model
DWFuzzyHipergeometricNaiveBayes Double Weighted Fuzzy Hipergeometric Naive Bayes
DWFuzzyHipergeometricNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, wdelta, weta, verbose = fuzzy_verbose() )DWFuzzyHipergeometricNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, wdelta, weta, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
wdelta |
vector weight each class |
weta |
vector weight each feature |
verbose |
logical; if |
A trained DWFuzzyHipergeometricNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Ferreira J, Machado LS, de Moraes RM (2025). “A New Double Weighted Fuzzy Hypergeometric Naive Bayes Network and its Application for User’s Assessment in Virtual Reality Simulators.” International Journal of Computational Intelligence Systems, 18(1), 1–17.
DWFuzzyHipergeometricNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "dw_hypergeometric") for the tidymodels interface.
set.seed(1) substituir_zero <- function(x) { if (x == 0) { while(1){ new_valor <- rhyper(1,3,30,10) if(new_valor != 0){ return(new_valor) } } } else { return(x) } } #Building dataframe class1 <- data.frame(rhyper(72,3,30,10), sample(seq(1,5),72,replace = TRUE), class = "Bem treinado") colnames(class1)[1] <- "sucessos" class1$sucessos <- sapply(class1$sucessos, substituir_zero) colnames(class1)[2] <- "tentativas" colnames(class1)[3] <- "avaliação" class2 <- data.frame(rhyper(72,3,17,12), sample(seq(4,7),72,replace = TRUE), class = "Mediano") colnames(class2)[1] <- "sucessos" #class2$sucessos <- ifelse(class2$sucessos == 0, 2, class2$sucessos) colnames(class2)[2] <- "tentativas" colnames(class2)[3] <- "avaliação" class3 <- data.frame(rhyper(72,3,9,11), sample(seq(7,10),72,replace = TRUE), class = "Precisa treinar") colnames(class3)[1] <- "sucessos" #class3$sucessos <- ifelse(class3$sucessos == 0, 3, class3$sucessos) colnames(class3)[2] <- "tentativas" colnames(class3)[3] <- "avaliação" data <- rbind(class1,class2,class3) # Weights weta1 <- c(0.22, 0.33, 0.45) wdelta1 <- c(0.33,0.33,0.33) #spliting dataframe split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") test <- Test[, -3] fit_NHT <- DWFuzzyHipergeometricNaiveBayes( train = Train[, -3], cl = Train[, 3], cores = 2, fuzzy = TRUE, wdelta = wdelta1, weta = weta1) pred_NHT <- predict(fit_NHT, test)set.seed(1) substituir_zero <- function(x) { if (x == 0) { while(1){ new_valor <- rhyper(1,3,30,10) if(new_valor != 0){ return(new_valor) } } } else { return(x) } } #Building dataframe class1 <- data.frame(rhyper(72,3,30,10), sample(seq(1,5),72,replace = TRUE), class = "Bem treinado") colnames(class1)[1] <- "sucessos" class1$sucessos <- sapply(class1$sucessos, substituir_zero) colnames(class1)[2] <- "tentativas" colnames(class1)[3] <- "avaliação" class2 <- data.frame(rhyper(72,3,17,12), sample(seq(4,7),72,replace = TRUE), class = "Mediano") colnames(class2)[1] <- "sucessos" #class2$sucessos <- ifelse(class2$sucessos == 0, 2, class2$sucessos) colnames(class2)[2] <- "tentativas" colnames(class2)[3] <- "avaliação" class3 <- data.frame(rhyper(72,3,9,11), sample(seq(7,10),72,replace = TRUE), class = "Precisa treinar") colnames(class3)[1] <- "sucessos" #class3$sucessos <- ifelse(class3$sucessos == 0, 3, class3$sucessos) colnames(class3)[2] <- "tentativas" colnames(class3)[3] <- "avaliação" data <- rbind(class1,class2,class3) # Weights weta1 <- c(0.22, 0.33, 0.45) wdelta1 <- c(0.33,0.33,0.33) #spliting dataframe split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") test <- Test[, -3] fit_NHT <- DWFuzzyHipergeometricNaiveBayes( train = Train[, -3], cl = Train[, 3], cores = 2, fuzzy = TRUE, wdelta = wdelta1, weta = weta1) pred_NHT <- predict(fit_NHT, test)
R6 implementation of the Double Weighted Fuzzy Hypergeometric Naive Bayes classifier. Create the model with
DWFuzzyHipergeometricNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
DWFuzzyHipergeometricNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> DWFuzzyHipergeometricNaiveBayes
DWFuzzyHipergeometricNaiveBayes$new()Create a new (untrained) classifier.
DWFuzzyHipergeometricNaiveBayes$new(fuzzy = TRUE, wdelta, weta)
fuzzywdeltawetaDWFuzzyHipergeometricNaiveBayes$clone()The objects of this class are cloneable with this method.
DWFuzzyHipergeometricNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- DWFuzzyHipergeometricNaiveBayesModel$new(wdelta = c(0.5, 0.5), weta = 1) x <- data.frame(s1 = c(1, 2, 1, 2), n1 = c(5, 5, 6, 6)) y <- factor(c("A", "A", "B", "B")) model$fit(train = x, cl = y) model$predict(x) modelmodel <- DWFuzzyHipergeometricNaiveBayesModel$new(wdelta = c(0.5, 0.5), weta = 1) x <- data.frame(s1 = c(1, 2, 1, 2), n1 = c(5, 5, 6, 6)) y <- factor(c("A", "A", "B", "B")) model$fit(train = x, cl = y) model$predict(x) model
ExpNBFuzzyParam Fuzzy Exponential Naive Bayes Classifier with Fuzzy parameters
ExpNBFuzzyParam( train, cl, alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6), cores = 2, verbose = fuzzy_verbose() )ExpNBFuzzyParam( train, cl, alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6), cores = 2, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases |
cl |
factor of true classifications of training set |
alphacut |
value of the alpha-cut parameter, this value is between 0 and 1. |
metd |
Method of transforming the triangle into scalar, It is the type of data entry for the test sample, use 'metd=1' if you want to use the Yager technique, 'metd=2' if you want to use the Q technique of the uniformity test (article: Directional Statistics and Shape analysis), 'metd=3' if you want to use the Thorani technique, 'metd=4' if you want to use the alpha-order technique and 'metd=5' if you want to use the GTFN technique (article: A novel approach for arithmetic operations and ranking of generalized fuzzy numbers with application). |
alp |
When metd for 4, it is necessary to have alp which are alpha-cut defined |
w |
When metd for 4, it is necessary to have w which are alpha-cut weights defined |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
verbose |
logical; if |
A trained ExpNBFuzzyParamModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Rodrigues AK, Batista TV, Moraes RM, Machado LS (2016). “A new exponential naive bayes classifier with fuzzy parameters.” In 2016 IEEE International Conference on Fuzzy Systems (FUZZ-IEEE), 1188–1194. IEEE.
ExpNBFuzzyParamModel for the R6 interface and fuzzy_naive_bayes() (engine "exponential_fuzzy_param") for the tidymodels interface.
set.seed(1) # determining a seed data(VirtualRealityData) # Splitting into Training and Testing split <- caTools::sample.split(t(VirtualRealityData[, 1]), SplitRatio = 0.7) Train <- subset(VirtualRealityData, split == "TRUE") Test <- subset(VirtualRealityData, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_FENB <- ExpNBFuzzyParam( train = Train[, -4], cl = Train[, 4], metd = 1, cores = 2 ) pred_FENB <- predict(fit_FENB, test) head(pred_FENB) head(Test[, 4])set.seed(1) # determining a seed data(VirtualRealityData) # Splitting into Training and Testing split <- caTools::sample.split(t(VirtualRealityData[, 1]), SplitRatio = 0.7) Train <- subset(VirtualRealityData, split == "TRUE") Test <- subset(VirtualRealityData, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_FENB <- ExpNBFuzzyParam( train = Train[, -4], cl = Train[, 4], metd = 1, cores = 2 ) pred_FENB <- predict(fit_FENB, test) head(pred_FENB) head(Test[, 4])
R6 implementation of the Exponential Naive Bayes with Fuzzy Parameters classifier. Create the model with
ExpNBFuzzyParamModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
ExpNBFuzzyParam() trains and returns an object of this class.
FuzzyClassifier -> ExpNBFuzzyParam
ExpNBFuzzyParam$new()Create a new (untrained) classifier.
ExpNBFuzzyParam$new( alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6) )
alphacutSee ExpNBFuzzyParam().
metdSee ExpNBFuzzyParam().
alpSee ExpNBFuzzyParam().
wSee ExpNBFuzzyParam().
ExpNBFuzzyParam$clone()The objects of this class are cloneable with this method.
ExpNBFuzzyParam$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- ExpNBFuzzyParamModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- ExpNBFuzzyParamModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
Parameter objects, for the dials package, of the main arguments of
fuzzy_naive_bayes(). They are used automatically by tune when an
argument is marked with tune().
fuzzy_membership(values = c(TRUE, FALSE)) alpha_cut(range = c(1e-04, 0.1), trans = NULL) ranking_method(range = c(1L, 5L), trans = NULL)fuzzy_membership(values = c(TRUE, FALSE)) alpha_cut(range = c(1e-04, 0.1), trans = NULL) ranking_method(range = c(1L, 5L), trans = NULL)
values |
A logical vector of possible values. |
range |
A two-element vector with the bounds of the parameter. |
trans |
A |
fuzzy_membership(): whether the membership functions are used
(argument fuzzy).
alpha_cut(): smallest alpha-cut of the fuzzy parameters (argument
alphacut).
ranking_method(): method used to rank the fuzzy numbers (argument
metd): 1 = Yager, 2 = Q distance, 3 = Thorani, 4 = alpha-order,
5 = GTFN.
These functions require the dials package.
A param object of the dials package.
fuzzy_membership() alpha_cut() ranking_method()fuzzy_membership() alpha_cut() ranking_method()
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.
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, ... )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, ... )
mode |
A single character string for the type of model. The only
possible value is |
engine |
A single character string specifying the classifier (see the table above). |
fuzzy |
Logical; whether the membership functions are used (argument
|
alpha_cut |
Smallest alpha-cut of the fuzzy parameters (argument
|
ranking_method |
Integer from 1 to 5: method used to rank the fuzzy
numbers (argument |
object |
A |
parameters |
A 1-row data frame (or |
fresh |
Logical; replace all the arguments ( |
... |
Engine-specific arguments to update. |
A model specification object with classes fuzzy_naive_bayes and
model_spec.
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)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)
By default, training a classifier prints a short progress message. Set
options(FuzzyClass.verbose = FALSE) to silence it globally (useful, for
example, when tuning many models with tidymodels), or use the argument
verbose of $fit() and of the functional interfaces.
fuzzy_verbose()fuzzy_verbose()
The value of the option FuzzyClass.verbose (default TRUE).
fuzzy_verbose() old <- options(FuzzyClass.verbose = FALSE) fit <- FuzzyGaussianNaiveBayes(iris[, -5], iris$Species) # silent options(old)fuzzy_verbose() old <- options(FuzzyClass.verbose = FALSE) fit <- FuzzyGaussianNaiveBayes(iris[, -5], iris$Species) # silent options(old)
FuzzyBayesRule Fuzzy Bayes Rule
FuzzyBayesRule(train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose())FuzzyBayesRule(train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose())
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyBayesRuleModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes R, Machado L (2008). “Fuzzy Bayes Rule for On-Line Training Assessment in Virtual Reality Simulators.” Multiple-Valued Logic and Soft Computing, 14, 325-338.
FuzzyBayesRuleModel for the R6 interface and fuzzy_naive_bayes() (engine "bayes_rule") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyBayesRule( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyBayesRule( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])
R6 implementation of the Fuzzy Bayes Rule classifier. Create the model with
FuzzyBayesRuleModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyBayesRule() trains and returns an object of this class.
FuzzyClassifier -> FuzzyBayesRule
FuzzyBayesRule$new()Create a new (untrained) classifier.
FuzzyBayesRule$new(fuzzy = TRUE)
fuzzySee FuzzyBayesRule().
FuzzyBayesRule$clone()The objects of this class are cloneable with this method.
FuzzyBayesRule$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyBayesRuleModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- FuzzyBayesRuleModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
FuzzyBetaNaiveBayes Fuzzy Beta Naive Bayes
FuzzyBetaNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyBetaNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyBetaNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Rodrigues AKG, Soares EAMG, Machado LS (2020). “A new fuzzy beta naive Bayes classifier.” In Developments of Artificial Intelligence Technologies in Computation and Robotics: Proceedings of the 14th International FLINS Conference (FLINS 2020), 437–445. World Scientific.
FuzzyBetaNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "beta") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") #---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyBetaNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") #---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyBetaNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])
R6 implementation of the Fuzzy Beta Naive Bayes classifier. Create the model with
FuzzyBetaNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyBetaNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyBetaNaiveBayes
FuzzyBetaNaiveBayes$new()Create a new (untrained) classifier.
FuzzyBetaNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyBetaNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyBetaNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyBetaNaiveBayesModel$new() model$fit(train = iris[, -5] / 10, cl = iris$Species) head(model$predict(iris[, -5] / 10)) head(model$predict(iris[, -5] / 10, type = "prob")) modelmodel <- FuzzyBetaNaiveBayesModel$new() model$fit(train = iris[, -5] / 10, cl = iris$Species) head(model$predict(iris[, -5] / 10)) head(model$predict(iris[, -5] / 10, type = "prob")) model
FuzzyBinomialNaiveBayes Fuzzy Binomial Naive Bayes
FuzzyBinomialNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyBinomialNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyBinomialNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Machado LS (2016). “A Fuzzy Binomial Naive Bayes classifier for epidemiological data.” In 2016 IEEE International Conference on Fuzzy Systems (FUZZ-IEEE), 745–750. IEEE.
FuzzyBinomialNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "binomial") for the tidymodels interface.
set.seed(1) # determining a seed class1 <- data.frame(vari1 = rbinom(100,size = 10, prob = 0.2), vari2 = rbinom(100,size = 10, prob = 0.2), vari3 = rbinom(100,size = 10, prob = 0.2), class = 1) class2 <- data.frame(vari1 = rbinom(100,size = 10, prob = 0.5), vari2 = rbinom(100,size = 10, prob = 0.5), vari3 = rbinom(100,size = 10, prob = 0.5), class = 2) class3 <- data.frame(vari1 = rbinom(100,size = 10, prob = 0.8), vari2 = rbinom(100,size = 10, prob = 0.8), vari3 = rbinom(100,size = 10, prob = 0.8), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- FuzzyBinomialNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])set.seed(1) # determining a seed class1 <- data.frame(vari1 = rbinom(100,size = 10, prob = 0.2), vari2 = rbinom(100,size = 10, prob = 0.2), vari3 = rbinom(100,size = 10, prob = 0.2), class = 1) class2 <- data.frame(vari1 = rbinom(100,size = 10, prob = 0.5), vari2 = rbinom(100,size = 10, prob = 0.5), vari3 = rbinom(100,size = 10, prob = 0.5), class = 2) class3 <- data.frame(vari1 = rbinom(100,size = 10, prob = 0.8), vari2 = rbinom(100,size = 10, prob = 0.8), vari3 = rbinom(100,size = 10, prob = 0.8), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- FuzzyBinomialNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])
R6 implementation of the Fuzzy Binomial Naive Bayes classifier. Create the model with
FuzzyBinomialNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyBinomialNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyBinomialNaiveBayes
FuzzyBinomialNaiveBayes$new()Create a new (untrained) classifier.
FuzzyBinomialNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyBinomialNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyBinomialNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyBinomialNaiveBayesModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) modelmodel <- FuzzyBinomialNaiveBayesModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) model
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).
paramsNamed list with the hyperparameters of the classifier.
estimatesList with the quantities estimated by $fit()
(NULL while the model has not been trained).
predictorsNames of the predictors seen during training.
classesClasses (levels of the response) seen during training.
n_obsNumber of training observations.
fit_timeTraining time, in seconds.
labelName of the classifier (read-only); it depends on whether
the membership functions are used (fuzzy).
FuzzyClassifier$new()Create a new (untrained) classifier.
FuzzyClassifier$new(...)
...Named hyperparameters of the classifier.
FuzzyClassifier$fit()Estimate the classifier from training data.
FuzzyClassifier$fit(train, cl, verbose = fuzzy_verbose())
trainMatrix or data frame of training set cases.
clFactor (or vector) of true classifications of the training set.
verboseLogical; if TRUE (default, see fuzzy_verbose()) a
message reports the training progress.
The trained object, invisibly.
FuzzyClassifier$predict()Classify new observations.
FuzzyClassifier$predict(newdata, type = c("class", "prob", "matrix", "raw"))
newdataMatrix 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".
A factor (type = "class") or a numeric matrix.
FuzzyClassifier$set_params()Update hyperparameters. The model is reset and must be
trained again with $fit().
FuzzyClassifier$set_params(...)
...Named hyperparameters, as in $new().
The object, invisibly.
FuzzyClassifier$is_fitted()Has the model been trained?
FuzzyClassifier$is_fitted()
TRUE or FALSE.
FuzzyClassifier$print()Print a summary of the classifier.
FuzzyClassifier$print(...)
...Ignored.
FuzzyClassifier$clone()The objects of this class are cloneable with this method.
FuzzyClassifier$clone(deep = FALSE)
deepWhether to make a deep clone.
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$labelmodel <- 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
FuzzyExponentialNaiveBayes Fuzzy Exponential Naive Bayes
FuzzyExponentialNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyExponentialNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyExponentialNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Machado LS (2016). “A fuzzy exponential naive bayes classifier.” In Uncertainty Modelling in Knowledge Engineering and Decision Making: Proceedings of the 12th International FLINS Conference, 207–212. World Scientific.
FuzzyExponentialNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "exponential") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyExponentialNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyExponentialNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])
R6 implementation of the Fuzzy Exponential Naive Bayes classifier. Create the model with
FuzzyExponentialNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyExponentialNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyExponentialNaiveBayes
FuzzyExponentialNaiveBayes$new()Create a new (untrained) classifier.
FuzzyExponentialNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyExponentialNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyExponentialNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyExponentialNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- FuzzyExponentialNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
FuzzyGammaNaiveBayes Fuzzy Gamma Naive Bayes
FuzzyGammaNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyGammaNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyGammaNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Soares EAMG, Machado LS (2018). “A Fuzzy Gamma Naive Bayes Classifier.” In Data Science and Knowledge Engineering for Sensing Decision Support: Proceedings of the 13th International FLINS Conference (FLINS 2018), 691–699. World Scientific.
FuzzyGammaNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "gamma") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyGammaNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyGammaNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])
R6 implementation of the Fuzzy Gamma Naive Bayes classifier. Create the model with
FuzzyGammaNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyGammaNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyGammaNaiveBayes
FuzzyGammaNaiveBayes$new()Create a new (untrained) classifier.
FuzzyGammaNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyGammaNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyGammaNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyGammaNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- FuzzyGammaNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
FuzzyGaussianNaiveBayes Fuzzy Gaussian Naive Bayes Classifier Zadeh-based
FuzzyGaussianNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyGaussianNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyGaussianNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Machado LS (2012). “Online Assessment in Medical Simulators Based on Virtual Reality Using Fuzzy Gaussian Naive Bayes.” Journal of Multiple-Valued Logic & Soft Computing, 18.
FuzzyGaussianNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "gaussian") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_GNB <- FuzzyGaussianNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_GNB <- predict(fit_GNB, test) head(pred_GNB) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_GNB <- FuzzyGaussianNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_GNB <- predict(fit_GNB, test) head(pred_GNB) head(Test[, 5])
R6 implementation of the Fuzzy Gaussian Naive Bayes (Zadeh-based) classifier. Create the model with
FuzzyGaussianNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyGaussianNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyGaussianNaiveBayes
FuzzyGaussianNaiveBayes$new()Create a new (untrained) classifier.
FuzzyGaussianNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyGaussianNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyGaussianNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyGaussianNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- FuzzyGaussianNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
FuzzyGeoNaiveBayes Naive Bayes Geometric Classifier
FuzzyGeoNaiveBayes(train, cl, cores = 2, fuzzy = T, verbose = fuzzy_verbose())FuzzyGeoNaiveBayes(train, cl, cores = 2, fuzzy = T, verbose = fuzzy_verbose())
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyGeoNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Ferreira J, Lopes A, Machado L, Moraes R (2023). “A Novel Fuzzy Geometric Naive Bayes Network for Online Skills Assessment in Training Based on Virtual Reality.” In Proceedings of the 15th International Joint Conference on Computational Intelligence, 395–401.
FuzzyGeoNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "geometric") for the tidymodels interface.
set.seed(1) # determining a seed class1 <- data.frame(vari1 = rgeom(100,prob = 0.2), vari2 = rgeom(100,prob = 0.2), vari3 = rgeom(100,prob = 0.2), class = 1) class2 <- data.frame(vari1 = rgeom(100,prob = 0.5), vari2 = rgeom(100,prob = 0.5), vari3 = rgeom(100,prob = 0.5), class = 2) class3 <- data.frame(vari1 = rgeom(100,prob = 0.9), vari2 = rgeom(100,prob = 0.9), vari3 = rgeom(100,prob = 0.9), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- FuzzyGeoNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])set.seed(1) # determining a seed class1 <- data.frame(vari1 = rgeom(100,prob = 0.2), vari2 = rgeom(100,prob = 0.2), vari3 = rgeom(100,prob = 0.2), class = 1) class2 <- data.frame(vari1 = rgeom(100,prob = 0.5), vari2 = rgeom(100,prob = 0.5), vari3 = rgeom(100,prob = 0.5), class = 2) class3 <- data.frame(vari1 = rgeom(100,prob = 0.9), vari2 = rgeom(100,prob = 0.9), vari3 = rgeom(100,prob = 0.9), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- FuzzyGeoNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])
R6 implementation of the Fuzzy Geometric Naive Bayes classifier. Create the model with
FuzzyGeoNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyGeoNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyGeoNaiveBayes
FuzzyGeoNaiveBayes$new()Create a new (untrained) classifier.
FuzzyGeoNaiveBayes$new(fuzzy = T)
fuzzySee FuzzyGeoNaiveBayes().
FuzzyGeoNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyGeoNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyGeoNaiveBayesModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) modelmodel <- FuzzyGeoNaiveBayesModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) model
FuzzyHipergeometricNaiveBayes Fuzzy Hipergeometric Naive Bayes
FuzzyHipergeometricNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyHipergeometricNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyHipergeometricNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Ferreira J, Machado LS, de Moraes RM (2025). “A New Double Weighted Fuzzy Hypergeometric Naive Bayes Network and its Application for User’s Assessment in Virtual Reality Simulators.” International Journal of Computational Intelligence Systems, 18(1), 1–17.
FuzzyHipergeometricNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "hypergeometric") for the tidymodels interface.
set.seed(1) # determining a seed substituir_zero <- function(x) { if (x == 0) { while(1){ new_valor <- rhyper(1,3,30,10) if(new_valor != 0){ return(new_valor) } } } else { return(x) } } #Building dataframe class1 <- data.frame(rhyper(72,3,30,10), sample(seq(1,5),72,replace = TRUE), class = "Bem treinado") colnames(class1)[1] <- "sucessos" class1$sucessos <- sapply(class1$sucessos, substituir_zero) colnames(class1)[2] <- "tentativas" colnames(class1)[3] <- "avaliação" class2 <- data.frame(rhyper(72,3,17,12), sample(seq(4,7),72,replace = TRUE), class = "Mediano") colnames(class2)[1] <- "sucessos" colnames(class2)[2] <- "tentativas" colnames(class2)[3] <- "avaliação" class3 <- data.frame(rhyper(72,3,9,11), sample(seq(7,10),72,replace = TRUE), class = "Precisa treinar") colnames(class3)[1] <- "sucessos" colnames(class3)[2] <- "tentativas" colnames(class3)[3] <- "avaliação" data <- rbind(class1,class2,class3) #spliting dataframe split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") test <- Test[, -3] fit_NHT <- FuzzyHipergeometricNaiveBayes( train = Train[, -3], cl = Train[, 3], cores = 2 ) pred_NHT <- predict(fit_NHT, test)set.seed(1) # determining a seed substituir_zero <- function(x) { if (x == 0) { while(1){ new_valor <- rhyper(1,3,30,10) if(new_valor != 0){ return(new_valor) } } } else { return(x) } } #Building dataframe class1 <- data.frame(rhyper(72,3,30,10), sample(seq(1,5),72,replace = TRUE), class = "Bem treinado") colnames(class1)[1] <- "sucessos" class1$sucessos <- sapply(class1$sucessos, substituir_zero) colnames(class1)[2] <- "tentativas" colnames(class1)[3] <- "avaliação" class2 <- data.frame(rhyper(72,3,17,12), sample(seq(4,7),72,replace = TRUE), class = "Mediano") colnames(class2)[1] <- "sucessos" colnames(class2)[2] <- "tentativas" colnames(class2)[3] <- "avaliação" class3 <- data.frame(rhyper(72,3,9,11), sample(seq(7,10),72,replace = TRUE), class = "Precisa treinar") colnames(class3)[1] <- "sucessos" colnames(class3)[2] <- "tentativas" colnames(class3)[3] <- "avaliação" data <- rbind(class1,class2,class3) #spliting dataframe split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") test <- Test[, -3] fit_NHT <- FuzzyHipergeometricNaiveBayes( train = Train[, -3], cl = Train[, 3], cores = 2 ) pred_NHT <- predict(fit_NHT, test)
R6 implementation of the Fuzzy Hypergeometric Naive Bayes classifier. Create the model with
FuzzyHipergeometricNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyHipergeometricNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyHipergeometricNaiveBayes
FuzzyHipergeometricNaiveBayes$new()Create a new (untrained) classifier.
FuzzyHipergeometricNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyHipergeometricNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyHipergeometricNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyHipergeometricNaiveBayesModel$new() x <- data.frame(s1 = c(1, 2, 1, 2), n1 = c(5, 5, 6, 6)) y <- factor(c("A", "A", "B", "B")) model$fit(train = x, cl = y) model$predict(x) modelmodel <- FuzzyHipergeometricNaiveBayesModel$new() x <- data.frame(s1 = c(1, 2, 1, 2), n1 = c(5, 5, 6, 6)) y <- factor(c("A", "A", "B", "B")) model$fit(train = x, cl = y) model$predict(x) model
FuzzyNaiveBayes Fuzzy Naive Bayes
FuzzyNaiveBayes( train, cl, fuzzy = TRUE, m = NULL, Pi = NULL, verbose = fuzzy_verbose() )FuzzyNaiveBayes( train, cl, fuzzy = TRUE, m = NULL, Pi = NULL, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases |
cl |
factor of true classifications of training set |
fuzzy |
boolean variable to use the membership function |
m |
is M/N, where M is the number of classes and N is the number of train lines |
Pi |
is 1/M, where M is the number of classes |
verbose |
logical; if |
A trained FuzzyNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Machado LS (2009). “Another approach for fuzzy naive bayes applied on online training assessment in virtual reality simulators.” In Proceedings of Safety Health and Environmental World Congress, 62–66.
FuzzyNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "naive") for the tidymodels interface.
set.seed(1) # determining a seed data(HouseVotes84) # Splitting into Training and Testing split <- caTools::sample.split(t(HouseVotes84[, 1]), SplitRatio = 0.7) Train <- subset(HouseVotes84, split == "TRUE") Test <- subset(HouseVotes84, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -1] fit_FNB <- FuzzyNaiveBayes( train = Train[, -1], cl = Train[, 1] ) pred_FNB <- predict(fit_FNB, test) head(pred_FNB) head(Test[, 1])set.seed(1) # determining a seed data(HouseVotes84) # Splitting into Training and Testing split <- caTools::sample.split(t(HouseVotes84[, 1]), SplitRatio = 0.7) Train <- subset(HouseVotes84, split == "TRUE") Test <- subset(HouseVotes84, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -1] fit_FNB <- FuzzyNaiveBayes( train = Train[, -1], cl = Train[, 1] ) pred_FNB <- predict(fit_FNB, test) head(pred_FNB) head(Test[, 1])
R6 implementation of the Fuzzy Naive Bayes classifier. Create the model with
FuzzyNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyNaiveBayes
FuzzyNaiveBayes$new()Create a new (untrained) classifier.
FuzzyNaiveBayes$new(fuzzy = TRUE, m = NULL, Pi = NULL)
fuzzySee FuzzyNaiveBayes().
mSee FuzzyNaiveBayes().
PiSee FuzzyNaiveBayes().
FuzzyNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- FuzzyNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
FuzzyPoissonNaiveBayes Fuzzy Poisson Naive Bayes
FuzzyPoissonNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyPoissonNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyPoissonNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Machado LS (2015). “A fuzzy poisson naive bayes classifier for epidemiological purposes.” In 2015 7th International Joint Conference on Computational Intelligence (IJCCI), volume 2, 193–198. IEEE.
FuzzyPoissonNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "poisson") for the tidymodels interface.
set.seed(1) # determining a seed class1 <- data.frame(vari1 = rpois(100,lambda = 2), vari2 = rpois(100,lambda = 2), vari3 = rpois(100,lambda = 2), class = 1) class2 <- data.frame(vari1 = rpois(100,lambda = 1), vari2 = rpois(100,lambda = 1), vari3 = rpois(100,lambda = 1), class = 2) class3 <- data.frame(vari1 = rpois(100,lambda = 5), vari2 = rpois(100,lambda = 5), vari3 = rpois(100,lambda = 5), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- FuzzyPoissonNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])set.seed(1) # determining a seed class1 <- data.frame(vari1 = rpois(100,lambda = 2), vari2 = rpois(100,lambda = 2), vari3 = rpois(100,lambda = 2), class = 1) class2 <- data.frame(vari1 = rpois(100,lambda = 1), vari2 = rpois(100,lambda = 1), vari3 = rpois(100,lambda = 1), class = 2) class3 <- data.frame(vari1 = rpois(100,lambda = 5), vari2 = rpois(100,lambda = 5), vari3 = rpois(100,lambda = 5), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_NBT <- FuzzyPoissonNaiveBayes( train = Train[, -4], cl = Train[, 4], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 4])
R6 implementation of the Fuzzy Poisson Naive Bayes classifier. Create the model with
FuzzyPoissonNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyPoissonNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyPoissonNaiveBayes
FuzzyPoissonNaiveBayes$new()Create a new (untrained) classifier.
FuzzyPoissonNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyPoissonNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyPoissonNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyPoissonNaiveBayesModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) modelmodel <- FuzzyPoissonNaiveBayesModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) model
FuzzyTrapezoidalNaiveBayes Fuzzy Naive Bayes Trapezoidal Classifier
FuzzyTrapezoidalNaiveBayes( train, cl, cores = 2, fuzzy = T, verbose = fuzzy_verbose() )FuzzyTrapezoidalNaiveBayes( train, cl, cores = 2, fuzzy = T, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyTrapezoidalNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Lopes A, Ferreira J, Machado LS, Moraes RM (2022). “A New Fuzzy Trapezoidal Naive Bayes Network as basis for Assessment in Training based on Virtual Reality.” In The 15th International FLINS Conference on Machine learning, Multi agent and Cyber physical systems (FLINS 2022). Nankai University.
FuzzyTrapezoidalNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "trapezoidal") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyTrapezoidalNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyTrapezoidalNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])
R6 implementation of the Fuzzy Trapezoidal Naive Bayes classifier. Create the model with
FuzzyTrapezoidalNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyTrapezoidalNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyTrapezoidalNaiveBayes
FuzzyTrapezoidalNaiveBayes$new()Create a new (untrained) classifier.
FuzzyTrapezoidalNaiveBayes$new(fuzzy = T)
fuzzyFuzzyTrapezoidalNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyTrapezoidalNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyTrapezoidalNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- FuzzyTrapezoidalNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
FuzzyTriangularNaiveBayes Fuzzy Naive Bayes Triangular Classifier
FuzzyTriangularNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )FuzzyTriangularNaiveBayes( train, cl, cores = 2, fuzzy = TRUE, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
fuzzy |
boolean variable to use the membership function |
verbose |
logical; if |
A trained FuzzyTriangularNaiveBayesModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Silva ILA, Machado LS (2020). “Online skills assessment in training based on virtual reality using a novel fuzzy triangular naive Bayes network.” In Developments of Artificial Intelligence Technologies in Computation and Robotics: Proceedings of the 14th International FLINS Conference (FLINS 2020), 446–454. World Scientific.
FuzzyTriangularNaiveBayesModel for the R6 interface and fuzzy_naive_bayes() (engine "triangular") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyTriangularNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_NBT <- FuzzyTriangularNaiveBayes( train = Train[, -5], cl = Train[, 5], cores = 2 ) pred_NBT <- predict(fit_NBT, test) head(pred_NBT) head(Test[, 5])
R6 implementation of the Fuzzy Triangular Naive Bayes classifier. Create the model with
FuzzyTriangularNaiveBayesModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
FuzzyTriangularNaiveBayes() trains and returns an object of this class.
FuzzyClassifier -> FuzzyTriangularNaiveBayes
FuzzyTriangularNaiveBayes$new()Create a new (untrained) classifier.
FuzzyTriangularNaiveBayes$new(fuzzy = TRUE)
fuzzyFuzzyTriangularNaiveBayes$clone()The objects of this class are cloneable with this method.
FuzzyTriangularNaiveBayes$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- FuzzyTriangularNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- FuzzyTriangularNaiveBayesModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
A dataset simulated containing training data from a Gamma Distribution
GamWeightDataGamWeightData
A dataset with 600 rows and 4 variables with 1 label.
GauNBFuzzyParam Fuzzy Gaussian Naive Bayes Classifier with Fuzzy parameters
GauNBFuzzyParam( train, cl, alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6), cores = 2, verbose = fuzzy_verbose() )GauNBFuzzyParam( train, cl, alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6), cores = 2, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
alphacut |
value of the alpha-cut parameter, this value is between 0 and 1. |
metd |
Method of transforming the triangle into scalar, It is the type of data entry for the test sample, use 'metd=1' if you want to use the Yager technique, 'metd=2' if you want to use the Q technique of the uniformity test (article: Directional Statistics and Shape analysis), 'metd=3' if you want to use the Thorani technique, 'metd=4' if you want to use the alpha-order technique and 'metd=5' if you want to use the GTFN technique (article: A novel approach for arithmetic operations and ranking of generalized fuzzy numbers with application). |
alp |
When metd for 4, it is necessary to have alp which are alpha-cut defined |
w |
When metd for 4, it is necessary to have w which are alpha-cut weights defined |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
verbose |
logical; if |
A trained GauNBFuzzyParamModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Moraes RM, Ferreira JA, Machado LS (2021). “A New Bayesian Network Based on Gaussian Naive Bayes with Fuzzy Parameters for Training Assessment in Virtual Simulators.” International Journal of Fuzzy Systems, 23(3), 849–861.
GauNBFuzzyParamModel for the R6 interface and fuzzy_naive_bayes() (engine "gaussian_fuzzy_param") for the tidymodels interface.
set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_FGNB <- GauNBFuzzyParam( train = Train[, -5], cl = Train[, 5], metd = 1, cores = 2 ) pred_FGNB <- predict(fit_FGNB, test) head(pred_FGNB) head(Test[, 5])set.seed(1) # determining a seed data(iris) # Splitting into Training and Testing split <- caTools::sample.split(t(iris[, 1]), SplitRatio = 0.7) Train <- subset(iris, split == "TRUE") Test <- subset(iris, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -5] fit_FGNB <- GauNBFuzzyParam( train = Train[, -5], cl = Train[, 5], metd = 1, cores = 2 ) pred_FGNB <- predict(fit_FGNB, test) head(pred_FGNB) head(Test[, 5])
R6 implementation of the Gaussian Naive Bayes with Fuzzy Parameters classifier. Create the model with
GauNBFuzzyParamModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
GauNBFuzzyParam() trains and returns an object of this class.
FuzzyClassifier -> GauNBFuzzyParam
GauNBFuzzyParam$new()Create a new (untrained) classifier.
GauNBFuzzyParam$new( alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6) )
alphacutSee GauNBFuzzyParam().
metdSee GauNBFuzzyParam().
alpSee GauNBFuzzyParam().
wSee GauNBFuzzyParam().
GauNBFuzzyParam$clone()The objects of this class are cloneable with this method.
GauNBFuzzyParam$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- GauNBFuzzyParamModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) modelmodel <- GauNBFuzzyParamModel$new() model$fit(train = iris[, -5], cl = iris$Species) head(model$predict(iris[, -5])) head(model$predict(iris[, -5], type = "prob")) model
This data set includes votes for each of the U.S. House of Representatives Congressmen on the 16 key votes identified by the CQA. The CQA lists nine different types of votes: voted for, paired for, and announced for (these three simplified to yea), voted against, paired against, and announced against (these three simplified to nay), voted present, voted present to avoid conflict of interest, and did not vote or otherwise make a position known (these three simplified to an unknown disposition).
data(HouseVotes84)data(HouseVotes84)
A data frame with 435 observations on 17 variables:
| 1 | Class Name: 2 (democrat, republican) |
| 2 | handicapped-infants: 2 (y,n) |
| 3 | water-project-cost-sharing: 2 (y,n) |
| 4 | adoption-of-the-budget-resolution: 2 (y,n) |
| 5 | physician-fee-freeze: 2 (y,n) |
| 6 | el-salvador-aid: 2 (y,n) |
| 7 | religious-groups-in-schools: 2 (y,n) |
| 8 | anti-satellite-test-ban: 2 (y,n) |
| 9 | aid-to-nicaraguan-contras: 2 (y,n) |
| 10 | mx-missile: 2 (y,n) |
| 11 | immigration: 2 (y,n) |
| 12 | synfuels-corporation-cutback: 2 (y,n) |
| 13 | education-spending: 2 (y,n) |
| 14 | superfund-right-to-sue: 2 (y,n) |
| 15 | crime: 2 (y,n) |
| 16 | duty-free-exports: 2 (y,n) |
| 17 | export-administration-act-south-africa: 2 (y,n) |
Source: Congressional Quarterly Almanac, 98th Congress, 2nd session 1984, Volume XL: Congressional Quarterly Inc., ington, D.C., 1985
Donor: Jeff Schlimmer ([email protected])
These data have been taken from the UCI Repository Of Machine Learning Databases at
and were converted to R format by Friedrich Leisch.
Newman, D.J. & Hettich, S. & Blake, C.L. & Merz, C.J. (1998). UCI Repository of machine learning databases [https://archive.ics.uci.edu/datasets]. Irvine, CA: University of California, Department of Information and Computer Science.
data(HouseVotes84) summary(HouseVotes84)data(HouseVotes84) summary(HouseVotes84)
PoiNBFuzzyParam Fuzzy Poisson Naive Bayes Classifier with Fuzzy parameters
PoiNBFuzzyParam( train, cl, alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6), cores = 2, verbose = fuzzy_verbose() )PoiNBFuzzyParam( train, cl, alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6), cores = 2, verbose = fuzzy_verbose() )
train |
matrix or data frame of training set cases. |
cl |
factor of true classifications of training set |
alphacut |
value of the alpha-cut parameter, this value is between 0 and 1. |
metd |
Method of transforming the triangle into scalar, It is the type of data entry for the test sample, use 'metd=1' if you want to use the Yager technique, 'metd=2' if you want to use the Q technique of the uniformity test (article: Directional Statistics and Shape analysis), 'metd=3' if you want to use the Thorani technique, 'metd=4' if you want to use the alpha-order technique and 'metd=5' if you want to use the GTFN technique (article: A novel approach for arithmetic operations and ranking of generalized fuzzy numbers with application). |
alp |
When metd for 4, it is necessary to have alp which are alpha-cut defined |
w |
When metd for 4, it is necessary to have w which are alpha-cut weights defined |
cores |
kept for backward compatibility; prediction is vectorized and does not start parallel workers (default = 2) |
verbose |
logical; if |
A trained PoiNBFuzzyParamModel R6 object (which inherits from FuzzyClassifier). Use predict(object, newdata, type = "class") or object$predict(newdata) to classify new observations; type = "prob" (or "matrix") returns the matrix of class probabilities.
Soares E, Machado L, Moraes R (2016). “Assessment of poisson naive bayes classifier with fuzzy parameters using data from different statistical distributions.” In IV Bazilian Congress on Fuzzy Sistems (CBSF 2016), volume 1, 57–68.
PoiNBFuzzyParamModel for the R6 interface and fuzzy_naive_bayes() (engine "poisson_fuzzy_param") for the tidymodels interface.
set.seed(1) # determining a seed class1 <- data.frame(vari1 = rpois(100,lambda = 2), vari2 = rpois(100,lambda = 2), vari3 = rpois(100,lambda = 2), class = 1) class2 <- data.frame(vari1 = rpois(100,lambda = 1), vari2 = rpois(100,lambda = 1), vari3 = rpois(100,lambda = 1), class = 2) class3 <- data.frame(vari1 = rpois(100,lambda = 5), vari2 = rpois(100,lambda = 5), vari3 = rpois(100,lambda = 5), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_FPoiNB <- PoiNBFuzzyParam( train = Train[, -4], cl = Train[, 4], metd = 1, cores = 2 ) pred_FPoiNB <- predict(fit_FPoiNB, test) head(pred_FPoiNB) head(Test[, 4])set.seed(1) # determining a seed class1 <- data.frame(vari1 = rpois(100,lambda = 2), vari2 = rpois(100,lambda = 2), vari3 = rpois(100,lambda = 2), class = 1) class2 <- data.frame(vari1 = rpois(100,lambda = 1), vari2 = rpois(100,lambda = 1), vari3 = rpois(100,lambda = 1), class = 2) class3 <- data.frame(vari1 = rpois(100,lambda = 5), vari2 = rpois(100,lambda = 5), vari3 = rpois(100,lambda = 5), class = 3) data <- rbind(class1,class2,class3) # Splitting into Training and Testing split <- caTools::sample.split(t(data[, 1]), SplitRatio = 0.7) Train <- subset(data, split == "TRUE") Test <- subset(data, split == "FALSE") # ---------------- # matrix or data frame of test set cases. # A vector will be interpreted as a row vector for a single case. test <- Test[, -4] fit_FPoiNB <- PoiNBFuzzyParam( train = Train[, -4], cl = Train[, 4], metd = 1, cores = 2 ) pred_FPoiNB <- predict(fit_FPoiNB, test) head(pred_FPoiNB) head(Test[, 4])
R6 implementation of the Poisson Naive Bayes with Fuzzy Parameters classifier. Create the model with
PoiNBFuzzyParamModel$new(), train it with $fit(train, cl) and classify new
observations with $predict(newdata). The functional interface
PoiNBFuzzyParam() trains and returns an object of this class.
FuzzyClassifier -> PoiNBFuzzyParam
PoiNBFuzzyParam$new()Create a new (untrained) classifier.
PoiNBFuzzyParam$new( alphacut = 1e-04, metd = 2, alp = c(0.35, 0.7, 0.86), w = c(0.1, 0.3, 0.6) )
alphacutSee PoiNBFuzzyParam().
metdSee PoiNBFuzzyParam().
alpSee PoiNBFuzzyParam().
wSee PoiNBFuzzyParam().
PoiNBFuzzyParam$clone()The objects of this class are cloneable with this method.
PoiNBFuzzyParam$clone(deep = FALSE)
deepWhether to make a deep clone.
model <- PoiNBFuzzyParamModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) modelmodel <- PoiNBFuzzyParamModel$new() x <- round(iris[, -5]) model$fit(train = x, cl = iris$Species) head(model$predict(x)) head(model$predict(x, type = "prob")) model
S3 interface to the $predict() method of the FuzzyClassifier R6 objects,
so that predict(model, newdata) keeps working as in previous versions.
## S3 method for class 'FuzzyClassifier' predict(object, newdata, type = "class", ...)## S3 method for class 'FuzzyClassifier' predict(object, newdata, type = "class", ...)
object |
A trained FuzzyClassifier object. |
newdata |
Matrix or data frame of test set cases. |
type |
|
... |
Ignored. |
A factor (type = "class") or a numeric matrix.
A dataset containing training data from Gammma Distribuition
SimulatedDataSimulatedData
A dataset with 600 rows and 4 variables with 1 label.
A dataset containing training data from a virtual reality simulator
VirtualRealityDataVirtualRealityData
A dataset with 600 rows and 4 variables with 1 label.