library(frbs) ## Load the Iris data data(iris) ## Shuffle the data irisShuffled <- iris[sample(nrow(iris)), ] ## Convert the response variable into numeric irisShuffled[,5] <- unclass( irisShuffled[, 5]) ## Split the data into training and testing datasets tra.iris <- irisShuffled[1 : 105, ] tst.iris <- irisShuffled[106 : nrow(irisShuffled), 1:4] ## Save actual values real.iris <- matrix(irisShuffled [106 : nrow(irisShuffled), 5], ncol = 1) ## Define the range of input variables range.data.input <- apply(iris[,-ncol(iris)], 2, range) ## Set parameter values method.type <- "FRBCS.W" control <- list(num.labels = 3, type.mf ="TRAPEZOID", type.tnorm = "MIN", type.snorm = "MAX", type.implication.func = "ZADEH") ## Construct an FRBS model mod.class <- frbs.learn(tra.iris, range.data.input, method.type, control) ## We can just display the frbsPMML format modPMML <- frbsPMML(mod.class) ## Export and save into "modClass.frbsPMML" write.frbsPMML(modPMML, "modClass") ## Import the frbsPMML format back to the FRBS model objectClass <- read.frbsPMML("modClass.frbsPMML") ## Predict new data (tst.iris) res.test <- predict(objectClass, tst.iris) ## Calculate error err = 100 * sum(real.iris != res.test)/ nrow(real.iris) print(err)