library(frbs)
## Warning: package 'frbs' was built under R version 4.1.2
data("iris", package = "datasets")
irisShuffled <- iris[sample(nrow(iris)), ]
irisShuffled[, 5] <- unclass(irisShuffled[, 5])
range.data.input <- apply(iris[, -ncol(iris)], 2, range)
tra.iris <- irisShuffled[1:140, ]
tst.iris <- irisShuffled[141:nrow(irisShuffled), 1:4]
real.iris <- matrix(irisShuffled[141:nrow(irisShuffled), 5], ncol = 1)
object.frbcs.w <- frbs.learn(tra.iris, range.data.input, method.type = 'FRBCS.W', control = list(num.labels = 3, type.mf = 'TRAPEZOID'))
summary(object.frbcs.w)
## The name of model: sim-0
## Model was trained using: FRBCS.W
## The names of attributes: Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## The interval of input data:
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## min 4.3 2.0 1.0 0.1
## max 7.9 4.4 6.9 2.5
## Type of FRBS model:
## [1] "FRBCS"
## Type of membership functions:
## [1] "TRAPEZOID"
## Type of t-norm method:
## [1] "Standard t-norm (min)"
## Type of s-norm method:
## [1] "Standard s-norm"
## Type of implication function:
## [1] "ZADEH"
## The names of linguistic terms on the input variables:
## [1] "small" "medium" "large" "small" "medium" "large" "small" "medium"
## [9] "large" "small" "medium" "large"
## The parameter values of membership function on the input variable (normalized):
## small medium large small medium large small medium large small medium
## [1,] 2.0 4.00 3.0 2.0 4.00 3.0 2.0 4.00 3.0 2.0 4.00
## [2,] 0.0 0.23 0.6 0.0 0.23 0.6 0.0 0.23 0.6 0.0 0.23
## [3,] 0.2 0.43 0.8 0.2 0.43 0.8 0.2 0.43 0.8 0.2 0.43
## [4,] 0.4 0.53 1.0 0.4 0.53 1.0 0.4 0.53 1.0 0.4 0.53
## [5,] NA 0.73 NA NA 0.73 NA NA 0.73 NA NA 0.73
## large
## [1,] 3.0
## [2,] 0.6
## [3,] 0.8
## [4,] 1.0
## [5,] NA
## The number of linguistic terms on each variables
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## [1,] 3 3 3 3 3
## The fuzzy IF-THEN rules:
## V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11
## 1 IF Sepal.Length is small and Sepal.Width is medium and Petal.Length is
## 2 IF Sepal.Length is small and Sepal.Width is small and Petal.Length is
## 3 IF Sepal.Length is large and Sepal.Width is medium and Petal.Length is
## 4 IF Sepal.Length is medium and Sepal.Width is large and Petal.Length is
## 5 IF Sepal.Length is medium and Sepal.Width is medium and Petal.Length is
## 6 IF Sepal.Length is medium and Sepal.Width is medium and Petal.Length is
## 7 IF Sepal.Length is medium and Sepal.Width is small and Petal.Length is
## 8 IF Sepal.Length is large and Sepal.Width is small and Petal.Length is
## 9 IF Sepal.Length is medium and Sepal.Width is small and Petal.Length is
## 10 IF Sepal.Length is small and Sepal.Width is large and Petal.Length is
## 11 IF Sepal.Length is large and Sepal.Width is large and Petal.Length is
## 12 IF Sepal.Length is small and Sepal.Width is small and Petal.Length is
## 13 IF Sepal.Length is medium and Sepal.Width is small and Petal.Length is
## 14 IF Sepal.Length is large and Sepal.Width is medium and Petal.Length is
## 15 IF Sepal.Length is large and Sepal.Width is medium and Petal.Length is
## 16 IF Sepal.Length is medium and Sepal.Width is medium and Petal.Length is
## 17 IF Sepal.Length is medium and Sepal.Width is medium and Petal.Length is
## 18 IF Sepal.Length is medium and Sepal.Width is small and Petal.Length is
## 19 IF Sepal.Length is small and Sepal.Width is medium and Petal.Length is
## 20 IF Sepal.Length is medium and Sepal.Width is small and Petal.Length is
## V12 V13 V14 V15 V16 V17 V18 V19 V20
## 1 small and Petal.Width is small THEN Species is 1
## 2 small and Petal.Width is small THEN Species is 1
## 3 large and Petal.Width is large THEN Species is 3
## 4 small and Petal.Width is small THEN Species is 1
## 5 large and Petal.Width is large THEN Species is 3
## 6 medium and Petal.Width is medium THEN Species is 2
## 7 medium and Petal.Width is medium THEN Species is 2
## 8 large and Petal.Width is large THEN Species is 3
## 9 large and Petal.Width is medium THEN Species is 3
## 10 small and Petal.Width is small THEN Species is 1
## 11 large and Petal.Width is large THEN Species is 3
## 12 medium and Petal.Width is medium THEN Species is 2
## 13 large and Petal.Width is large THEN Species is 3
## 14 large and Petal.Width is medium THEN Species is 3
## 15 medium and Petal.Width is medium THEN Species is 2
## 16 medium and Petal.Width is large THEN Species is 3
## 17 large and Petal.Width is medium THEN Species is 3
## 18 medium and Petal.Width is large THEN Species is 3
## 19 medium and Petal.Width is medium THEN Species is 2
## 20 large and Petal.Width is medium THEN Species is 2
## The certainty factor:
##
## [1,] 0.4002462
## [2,] 0.4002462
## [3,] 0.6923400
## [4,] 0.4002462
## [5,] 0.6923400
## [6,] 0.4074138
## [7,] 0.4074138
## [8,] 0.6923400
## [9,] 0.6923400
## [10,] 0.4002462
## [11,] 0.6923400
## [12,] 0.4074138
## [13,] 0.6923400
## [14,] 0.6923400
## [15,] 0.4074138
## [16,] 0.6923400
## [17,] 0.6923400
## [18,] 0.6923400
## [19,] 0.4074138
## [20,] 0.4074138
pred <- predict(object.frbcs.w, tst.iris)
pred
## [,1]
## [1,] 2
## [2,] 2
## [3,] 2
## [4,] 3
## [5,] 2
## [6,] 1
## [7,] 3
## [8,] 3
## [9,] 1
## [10,] 3
err <- 100 * sum(pred != real.iris) / length(pred)
err
## [1] 40