mcfs | R Documentation |
Performs Monte Carlo Feature Selection (MCFS-ID) on a given data set. The data set should define a classification problem with discrete/nominal class labels. This function returns features sorted by RI as well as cutoff value, ID-Graph edges that denote interdependencies (ID), evaluation of top features and other statistics.
mcfs(formula, data,
attrWeights = NULL,
projections = 'auto',
projectionSize = 'auto',
featureFreq = 100,
splits = 5,
splitSetSize = 500,
balance = 'auto',
cutoffMethod = c("permutations", "criticalAngle", "kmeans", "mean", "contrast"),
cutoffPermutations = 20,
mode = 1,
buildID = TRUE,
finalRuleset = TRUE,
finalCV = TRUE,
finalCVSetSize = 1000,
seed = NA,
threadsNumber = 4)
formula |
specifies decision attribute and relation between class and other attributes (e.g. |
data |
defines input data.frame containing all features with decision attribute included. This data.frame must contain proper types of columns. Columns |
attrWeights |
defines vector of |
projections |
defines the number of subsets (projections) with randomly selected features. This parameter is usually set to a few thousands and is denoted in the paper as s. By default it is set to 'auto' and this value is based on size of input data set and featureFreq parameter. |
projectionSize |
defines the number of features in one subset. It can be defined by an absolute value (e.g. 100 denotes 100 randomly selected features) or by a fraction of input attributes (e.g. 0.05 denotes 5% of input features). This parameter is denoted in the paper as m. If is set to 'auto' then projectionSize equals to
|
featureFreq |
determines how many times each input feature should be randomly selected when |
splits |
defines the number of splits of each subset. This parameter is denoted in the paper as t. The size of the training set in the input subset is always set on 66%. |
splitSetSize |
determines whether to limit input dataset size. It helps to speedup computation for data sets with a large number of objects. If the parameter is larger than 1, it determines the number of objects that are drawn at random for each of the |
balance |
determines the way to balance classes. It should be set to 2 or higher if input dataset contains heavily unbalanced classes. Each subset s will contain all the objects from the least frequent class and randomly selected set of objects from each of the remaining classes. This option helps to select features that are important for discovering a relatively rare class. The parameter defines the maximal imbalance ratio. If the ratio is set to 2, then subset s will contain the number of objects from each class (but the least frequent one) proportional to the square root of the class size |
cutoffMethod |
determines the final cutoff method. Default value is 'permutations'. The methods of finding cutoff value between important and unimportant attributes are the following:
|
cutoffPermutations |
determines the number of permutation runs. It needs at least 20 permutations ( |
mode |
determines number of stages in MCFS filtering. If |
buildID |
if |
finalRuleset |
if |
finalCV |
if |
finalCVSetSize |
limits the number of objects used in the final cv experiment. For each out of 3 cv repetitions, the objects are selected randomly from the uniform distribution. |
seed |
seed for random number generator in Java. By default the seed is random. Replication of the result is possible only if |
threadsNumber |
number of threads to use in computation. More threads needs more CPU cores as well as memory usage is a bit higher. It is recommended to set this value equal to or less than CPU available cores. |
data |
input data.frame limited to the top important features set. |
target |
decision attribute name. |
RI |
data.frame that contains all features with relevance scores sorted from the most relevant to the least relevant. This is the ranking of features. |
ID |
data.frame that contains features interdependencies as graph edges. It can be converted into a graph object by |
distances |
data.frame that contains convergence statistics of subsequent projections. |
cmatrix |
confusion matrix obtained from all |
cutoff |
data.frame that contains cutoff values obtained by the following methods: mean, kmeans, criticalAngle, permutations (max RI). |
cutoff_value |
the number of features chosen as informative by the method defined by parameter |
cv_accuracy |
data.frame that contains classification results obtained by cross validation performed on |
permutations |
this data.frame contains the following results of permutation experiments:
|
jrip |
classification rules produced by ripper algorithm and related cross validation result obtained for top features. |
params |
all settings used by MCFS-ID. |
exec_time |
execution time of MCFS-ID. |
M. Draminski, J. Koronacki (2018),"rmcfs: An R Package for Monte Carlo Feature Selection and Interdependency Discovery", Journal of Statistical Software, vol 85(12), 1-28, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v085.i12")}
## Not run: ###dontrunbegin
####################################
######### Artificial data ##########
####################################
# Set VM size for Java
options(java.parameters = "-Xmx8g")
library(rmcfs)
# create input data and review it
adata <- artificial.data(rnd_features = 10)
showme(adata)
# Parametrize and run MCFS-ID procedure
result <- mcfs(class~., adata, cutoffPermutations = 3, featureFreq = 50,
buildID = TRUE, finalCV = FALSE, finalRuleset = FALSE,
threadsNumber = 2)
# Print basic information about mcfs result
print(result)
# Review cutoff values for all methods
print(result$cutoff)
# Review cutoff value used in plots
print(result$cutoff_value)
# Plot & print out distances between subsequent projections.
# These are convergence MCFS-ID statistics.
plot(result, type = "distances")
print(result$distances)
# Plot & print out 50 most important features and show max RI values from
# permutation experiment.
plot(result, type = "ri", size = 50)
print(head(result$RI, 50))
# Plot & print out 50 strongest feature interdependencies.
plot(result, type = "id", size = 50)
print(head(result$ID, 50))
# Plot features ordered by RI. Parameter 'size' is the number of
# top features in the chart. By default it is set on cutoff_value + 10
plot(result, type = "features", cex = 1)
# Here we set 'size' at fixed value 10.
plot(result, type = "features", size = 10)
# Plot cv classification result obtained on top features.
# In the middle of x axis red label denotes cutoff_value.
# plot(result, type = "cv", cv_measure = "wacc", cex = 0.8)
# Plot & print out confusion matrix. This matrix is the result of
# all classifications performed by all decision trees on all s*t datasets.
plot(result, type = "cmatrix")
# build interdependencies graph (all default parameters).
gid <- build.idgraph(result)
plot(gid, label_dist = 1)
# build interdependencies graph for top 6 features
# and top 12 interdependencies and plot all nodes
gid <- build.idgraph(result, size = 6, size_ID = 12, orphan_nodes = TRUE)
plot(gid, label_dist = 1)
# Export graph to graphML (XML structure)
path <- tempdir()
igraph::write_graph(gid, file = file.path(path, "artificial.graphml"),
format = "graphml", prefixAttr = FALSE)
# Export and import results to/from csv files
export.result(result, path = path, label = "artificial")
result <- import.result(path = path, label = "artificial")
# Find out how many trees with the given attribute has been built (and nodes based the
# attribute in total). Notice that result$RI$projections keeps the number of subsets where
# the feature was randomly picked. The value: result$RI$projections*result$params$mcfs.splits
# is the total number of trees for a given attribute that could be built based on the attribute.
# This normalization takes into the consideration not the full number of st trees
# but only the fraction that is trained on datasets with the attribute.
result$RI$classifiers*(result$RI$projections*result$params$mcfs.splits)
result$RI$nodes*(result$RI$projections*result$params$mcfs.splits)
####################################
########## Alizadeh data ###########
####################################
# Load Alizadeh dataset.
# A 4026 x 62 gene expression data matrix of log-ratio values. The last column contains
# the annotations of the 62 samples with respect to the cancer types C, D, F.
# The data are from the lymphoma/leukemia study of A. Alizadeh et al., Nature 403:503-511 (2000),
# http://llmpp.nih.gov/lymphoma/index.shtml
alizadeh <- read.csv(file="http://home.ipipan.waw.pl/m.draminski/files/data/alizadeh.csv",
stringsAsFactors = FALSE)
showme(alizadeh)
# Fix data types and data values - replace characters such as "," " " "/" etc.
# from values and column names and fix data types
# This function may help if mcfs has any problems with input data
alizadeh <- fix.data(alizadeh)
# Run MCFS-ID procedure on default parameters.
# For larger real data (thousands of features) default 'auto' settings are the best.
# This example may take 10-20 minutes but this one is a real dataset with 4026 features.
# Set up more threads according to your CPU cores number.
result <- mcfs(class~., alizadeh, featureFreq = 100, cutoffPermutations = 10, threadsNumber = 8)
# Print basic information about mcfs result.
print(result)
# Plot & print out distances between subsequent projections.
plot(result, type="distances")
# Show RI values for top 500 features and max RI values from permutation experiment.
plot(result, type = "ri", size = 500)
# Plot heatmap on top features, only numeric features are presented
plot(result, type = "heatmap", size = 20, heatmap_norm = 'norm', heatmap_fun = 'median')
# Plot cv classification result obtained on top features.
# In the middle of x axis red label denotes cutoff_value.
plot(result, type = "cv", cv_measure = "wacc", cex = 0.8)
# build interdependencies graph.
gid <- build.idgraph(result, size = 20)
plot.idgraph(gid, label_dist = 0.3)
## End(Not run)###dontrunend
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.