##############################################################
## A.1 Example: Basic concepts of rough set theory
##############################################################
## Using hiring data set, see RoughSetData doc
data(RoughSetData)
decision.table <- RoughSetData$hiring.dt
## define considered attributes which are first, second and
## third attributes
attr.P <- c(1,2,3)
####### compute indiscernibility relation #######
IND <- BC.IND.relation.RST(decision.table, attribute = attr.P)
####### compute lower and upper approximations #####
## Let us define fourth index as the decision attribute
decision.attr <- c(4)
roughset <- BC.LU.approximation.RST(decision.table, IND, decision.attr)
####### Determine regions ######
region.RST <- BC.positive.reg.RST(decision.table, roughset)
####### The decision-relative discernibility matrix and reduct #####
disc.mat <- BC.discernibility.mat.RST(decision.table, range.object = NULL)
##############################################################
## A.2 Example: Basic concepts of fuzzy rough set theory
##############################################################
## Using pima7 data set, see RoughSetData doc
data(RoughSetData)
decision.table <- RoughSetData$pima7.dt
## In this case, let us consider the first and second attributes
conditional.attr <- c(1, 2)
## We are using "lukasiewicz" t-norm and "tolerance" relation
## with "eq.1" as fuzzy similarity equation
control.ind <- list(type.aggregation = c("t.tnorm", "lukasiewicz"),
type.relation = c("tolerance", "eq.1"))
## Compute fuzzy indiscernibility relation
IND.condAttr <- BC.IND.relation.FRST(decision.table, attributes = conditional.attr,
control = control.ind)
## Compute fuzzy lower and upper approximation using type.LU : "implicator.tnorm"
## Define index of decision attribute
decision.attr = c(9)
## Compute fuzzy indiscernibility relation of decision attribute
## We are using "crisp" for type of aggregation and type of relation
control.dec <- list(type.aggregation = c("crisp"), type.relation = "crisp")
IND.decAttr <- BC.IND.relation.FRST(decision.table, attributes = decision.attr,
control = control.dec)
## Define control parameter containing type of implicator and t-norm
control <- list(t.implicator = "lukasiewicz", t.tnorm = "lukasiewicz")
## Compute fuzzy lower and upper approximation
FRST.LU <- BC.LU.approximation.FRST(decision.table, IND.condAttr, IND.decAttr,
type.LU = "implicator.tnorm", control = control)
## Determine fuzzy positive region and its degree of dependency
fuzzy.region <- BC.positive.reg.FRST(decision.table, FRST.LU)
###############################################################
## B Example : Data analysis based on RST and FRST
## In this example, we are using wine dataset for both RST and FRST
###############################################################
## Using wine data set, see RoughSetData doc
data(RoughSetData)
wine.decTable <- SF.asDecisionTable(dataset = RoughSetData$wine.dt[6 : 178, ],
decision.attr = 14, indx.nominal = 14)
## define first five instances as newdata or testing data
tst.wine <- SF.asDecisionTable(dataset = wine.decTable[1:5, -ncol(wine.decTable)])
###############################################################
## B.1 Example : Rough Set Theory
###############################################################
##### DISCRETIZATION STEP
## In this example, we are using local strategy algorithm
cut.values.tra <- D.discretization.RST(wine.decTable,
type.method = "global.discernibility")
## generate new decision table
d.new.tra.rst <- SF.applyDecTable(wine.decTable, cut.values.tra)
d.new.tst.rst <- SF.applyDecTable(tst.wine, cut.values.tra)
##### FEATURE SELECTION STEP
## In this example, we are using permutation algorithm
## which generates a single superreduct
red.rst <- FS.feature.subset.computation(d.new.tra.rst,
method = "quickreduct.rst")
## generate new decision table according to the reduct (optional)
fs.new.decTable.rst <- SF.applyDecTable(d.new.tra.rst, red.rst)
##### RULE INDUCTION
## In this case, we are using the original decision table,
## we also can use the decision table resulting from feature selection
rules.rst <- RI.indiscernibilityBasedRules.RST(d.new.tra.rst, red.rst)
## predicting newdata
res.1 <- predict(rules.rst, d.new.tst.rst)
###############################################################
## B.2 Example : Fuzzy Rough Set Theory
###############################################################
## FEATURE SELECTION STEP
red.frst <- FS.feature.subset.computation(wine.decTable,
method = "quickreduct.frst")
fs.new.decTable.frst <- SF.applyDecTable(decision.table = wine.decTable, red.frst)
## INSTANCE SELECTION STEP
## It should be noted in this case we are using the decision table
## that results from feature selection
is.object <- IS.FRIS.FRST(decision.table = fs.new.decTable.frst, control =
list(threshold.tau = 0.4, alpha = 1))
is.new.decTable.frst <- SF.applyDecTable(decision.table = fs.new.decTable.frst, is.object)
## CLASSIFIER
## Predict the testing data by using the FRNN.O method
control <- list(m = 2, type.membership = "gradual")
new.tst.wine <- SF.applyDecTable(decision.table = tst.wine, red.frst)
## Compute predictions
pred.class <- C.FRNN.O.FRST(decision.table = is.new.decTable.frst, newdata = new.tst.wine,
control = control)
## RULE INDUCTION
control <- list(type.aggregation = c("t.tnorm", "lukasiewicz"),
type.relation = c("tolerance", "eq.3"), t.implicator = "lukasiewicz")
rules.hybrid <- RI.hybridFS.FRST(decision.table = is.new.decTable.frst, control)
## predicting newdata
res.1 <- predict(rules.hybrid, tst.wine)
Run the code above in your browser using DataLab