FuzzyClass

CRAN version CRAN Download

Last update: 05-11-2022

A family of probabilities-based classifiers Fuzzy and Non-Fuzzy

Installation

# Installation
install.packages("devtools")
devtools::install_github("Jodavid/FuzzyClass")

Usage

# package import
library(FuzzyClass)

Data reading and preparation for use


library(FuzzyClass)
library(caret)

#' ---------------------------------------------
#' The following shows how the functions are used:
#' --------------
#' Reading a database:
#'
#' Actual training data:
data(VirtualRealityData)

VirtualRealityData <- as.data.frame(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")
# ----------------

test = Test[,-4]

Fuzzy Gaussian Naive Bayes with Fuzzy Parameters

# --------------------------------------------------
# Fuzzy Gaussian Naive Bayes with Fuzzy Parameters


fit_FGNB <- GauNBFuzzyParam(train =  Train[,-4],
                                    cl = Train[,4], metd = 2, cores = 1)


print(fit_FGNB)
#> 
#> Fuzzy Gaussian Naive Bayes Classifier for Discrete Predictors
#> 
#> Variables:
#> [1] "V1" "V2" "V3"
#> Class:
#> [1] "1" "2" "3"
saida <- predict(fit_FGNB, test)
confusionMatrix(factor(Test[,4]), saida)
#> Confusion Matrix and Statistics
#> 
#>           Reference
#> Prediction  1  2  3
#>          1 55  8  1
#>          2  5 42 12
#>          3  1  9 47
#> 
#> Overall Statistics
#>                                          
#>                Accuracy : 0.8            
#>                  95% CI : (0.734, 0.8558)
#>     No Information Rate : 0.3389         
#>     P-Value [Acc > NIR] : <2e-16         
#>                                          
#>                   Kappa : 0.6999         
#>                                          
#>  Mcnemar's Test P-Value : 0.772          
#> 
#> Statistics by Class:
#> 
#>                      Class: 1 Class: 2 Class: 3
#> Sensitivity            0.9016   0.7119   0.7833
#> Specificity            0.9244   0.8595   0.9167
#> Pos Pred Value         0.8594   0.7119   0.8246
#> Neg Pred Value         0.9483   0.8595   0.8943
#> Prevalence             0.3389   0.3278   0.3333
#> Detection Rate         0.3056   0.2333   0.2611
#> Detection Prevalence   0.3556   0.3278   0.3167
#> Balanced Accuracy      0.9130   0.7857   0.8500

saida <- predict(fit_FGNB, test, type = "matrix")