Perform variable selection for Bayesian networks of class MoTBF.
variableSelection(
data,
dag,
loss,
target = NULL,
order = NULL,
method = "forward",
fit.args = NULL,
loss.args = NULL,
cv.args = NULL,
verbose = TRUE
)A list of 4 elements
a "data.frame" of the selected variables, including the target.
the index of the selected variables (with respect to the input dataset), including the target.
the loss value of the best model.
an object of class "motbf.fit.cv", containing the result of the cross-validation of the best model.
an object of class "data.frame", which can contain continuous and discrete variables.
a character string indicating the structural learning algorithm to be applied to the training data. Available options are naive Bayes (NB), tree augmented naive Bayes (TAN) and hill-climbing (HC).
a character string indicating which loss function should be used. Currently, two options are available: 'logl', for the log-likelihood of the model; and 'pred', for the predictive error. See details.
a character string indicating which node is the target.
a character vector indicating the order in which the predictive variables are included in the model. If it is NULL, the predictors are ordered regarding their mutual information with the target variable.
a character vector indicating the method used for the variable selection. Available methods are 'forward' (default), 'gf' (greedy forward selection) and 'iwsr' (Incremental Wrapper Sequential Subset with Replacement).
a list containing optional arguments used to fit the models. These arguments must be those accepted by function motbf.fit, i.e., 'numIntervals' (4), 'POTENTIAL_TYPE' ('MOP'), 'maxParam' (NULL), 's' (NULL), 'priorData' (NULL) or 'scale' (TRUE). If fit.args is left NULL, the default values (in brackets) for those arguments will be used.
a list containing optional arguments related to the loss functions. Currently available arguments are: 'loss.matrix' and 'percentage_test'. See details.
a list containing optional arguments related to the cross-validation method. Currently available arguments are: 'k', 'seed'. See details.
Logical; if TRUE, prints execution messages and progress updates to the console.
A filter-wrapper variable selection procedure is implemented.
Firstly, the explanatory variables are ordered according to their mutual information
with the target variable, unless argument 'order' is not null, in which case
the given order is followed.
Then, the first variable in the ordered set and the target are used to fit an initial model.
The model is validated by means of a k-fold cross validation (cv.args[[k]] >= 2).
However, it is possible to validate on a test set (cv.args[[k]] = 1), or on the same training set (cv.args[[k]] = 0).
The model is evaluated in terms of its log-likelihood (loss = 'logl') or its predictive accuracy (loss = 'pred').
In the latter case, the root mean squared error is computed for regression models,
whereas the classification accuracy is computed for classification models.
Afterwards, the remaining explanatory variables are included in the model, one by one, according to the aforementioned order,
and a new model is obtained. Whenever the inclusion of a variable increases the accuracy of the model
(increases its log-likelihood or classification error, or decreases its root mean squared error), it is kept; otherwise,
it is excluded from the model.
Details on the loss argument:
'logl'The log-likelihood of the model is computed. This measure is available for both basis functions, MTE and MOP.
'pred'This option is only available for MOPs. The predictive error (root mean squared error) or classification accuracy is computed as the loss function, depending on the nature of the target variable (continuous or discrete, respectively). The program will guess which type the target variable is and compute the corresponding measure.
Details on the loss.args argument. Currently, two arguments can be specified within this list:
'p.test'Only used if k = 1.
This argument specifies the proportion of the data set that goes to the test set (between 0 and 1).
'loss.matrix'A squared matrix used to compute a weighted classification accuracy for discrete targets.
This matrix is multiplied by the confusion matrix element by element,
and the resulting matrix is used to compute the classification accuracy.
The loss matrix allows to increase the penalty of some user-specified errors.
If the loss matrix provided is a constant matrix of ones, the result is the standard classification accuracy.
Note that the diagonal of the loss matrix is regarded as a reward, while the off-diagonal is regarded as a cost.
Details in the cv.args argument. Currently, two arguments can be specified within this list:
kan integer indicating the number of folds to split the data set. If k = 0, the train and test sets are the same data; if k = 1, hold-out validation is carried out, i.e., the data set is split in train (80% by default) and test (20% by default); finally, if k >=2, k-fold cross validation is carried out.
seedan integer to specify the seed. The k-folds are created randomly, so one might expect slightly different results unless 'seed' is used.
#################
### EXAMPLE 1 ###
#################
# Perform variable selection on the iris dataset.
# Use the TAN structure as DAG and the Species variable as target.
vs = variableSelection(iris, dag = 'TAN', loss = 'pred', target = 'Species',
cv.args = list(k = 1, seed = 1023))
# Check out the results of the best model.
summary(vs$crossvalidation)
Run the code above in your browser using DataLab