## ## ## Not run: #We use the pima dataset for this example #We need to convert the output in a numeric format. ## Start input data library(fugeR) load("pima.5f.RData") tra.pima.1 <- data.frame(pima.5.1.tra) tra.pima.2 <- data.frame(pima.5.2.tra) tra.pima.3 <- data.frame(pima.5.3.tra) tra.pima.4 <- data.frame(pima.5.4.tra) tra.pima.5 <- data.frame(pima.5.5.tra) tst.pima.1 <- data.frame(pima.5.1.tst[, 1 : 8]) tst.pima.2 <- data.frame(pima.5.2.tst[, 1 : 8]) tst.pima.3 <- data.frame(pima.5.3.tst[, 1 : 8]) tst.pima.4 <- data.frame(pima.5.4.tst[, 1 : 8]) tst.pima.5 <- data.frame(pima.5.5.tst[, 1 : 8]) real.pima.1 <- data.frame(matrix(pima.5.1.tst[, 9], ncol = 1)) real.pima.2 <- data.frame(matrix(pima.5.2.tst[, 9], ncol = 1)) real.pima.3 <- data.frame(matrix(pima.5.3.tst[, 9], ncol = 1)) real.pima.4 <- data.frame(matrix(pima.5.4.tst[, 9], ncol = 1)) real.pima.5 <- data.frame(matrix(pima.5.5.tst[, 9], ncol = 1)) #Launch the evolution, fugeR.run will return #the best fuzzy system found during the evolution ## 1 fuzzySystem.1 <- fugeR.run( tra.pima.1[, 1:8], tra.pima.1[, 9, drop = FALSE], generation=100, # Increase the number of generation for a better accuracy population=100, elitism=20, verbose=TRUE, threshold=NA, sensiW=0.0, speciW=0.0, accuW=0.0, rmseW=1.0, maxRules=10, maxVarPerRule=2, labelsMf=3 ) ## 2 fuzzySystem.2 <- fugeR.run( tra.pima.2[, 1:8], tra.pima.2[, 9, drop = FALSE], generation=100, # Increase the number of generation for a better accuracy population=100, elitism=20, verbose=TRUE, threshold=NA, sensiW=0.0, speciW=0.0, accuW=0.0, rmseW=1.0, maxRules=10, maxVarPerRule=2, labelsMf=3 ) ## 3 fuzzySystem.3 <- fugeR.run( tra.pima.3[, 1:8], tra.pima.3[, 9, drop = FALSE], generation=100, # Increase the number of generation for a better accuracy population=100, elitism=20, verbose=TRUE, threshold=NA, sensiW=0.0, speciW=0.0, accuW=0.0, rmseW=1.0, maxRules=10, maxVarPerRule=2, labelsMf=3 ) ## 4 fuzzySystem.4 <- fugeR.run( tra.pima.4[, 1:8], tra.pima.4[, 9, drop = FALSE], generation=100, # Increase the number of generation for a better accuracy population=100, elitism=20, verbose=TRUE, threshold=NA, sensiW=0.0, speciW=0.0, accuW=0.0, rmseW=1.0, maxRules=10, maxVarPerRule=2, labelsMf=3 ) ## 5 fuzzySystem.5 <- fugeR.run( tra.pima.5[, 1:8], tra.pima.5[, 9, drop = FALSE], generation=100, # Increase the number of generation for a better accuracy population=100, elitism=20, verbose=TRUE, threshold=NA, sensiW=0.0, speciW=0.0, accuW=0.0, rmseW=1.0, maxRules=10, maxVarPerRule=2, labelsMf=3 ) #Plot the predicton given by the best fuzzy system found during the evolution pred.1 <- round(fugeR.predict(fuzzySystem.1, tst.pima.1)) pred.2 <- round(fugeR.predict(fuzzySystem.2, tst.pima.2)) pred.3 <- round(fugeR.predict(fuzzySystem.3, tst.pima.3)) pred.4 <- round(fugeR.predict(fuzzySystem.4, tst.pima.4)) pred.5 <- round(fugeR.predict(fuzzySystem.5, tst.pima.5)) err.1 = 100*sum(real.pima.1!=pred.1)/nrow(real.pima.1) err.2 = 100*sum(real.pima.2!=pred.2)/nrow(real.pima.2) err.3 = 100*sum(real.pima.3!=pred.3)/nrow(real.pima.3) err.4 = 100*sum(real.pima.4!=pred.4)/nrow(real.pima.4) err.5 = 100*sum(real.pima.5!=pred.5)/nrow(real.pima.5) err.aver <- (err.1 + err.2 + err.3 + err.4 +err.5)/5 print(err.aver)