LVQs_train {nnlib2Rcpp} | R Documentation |
Train a Supervised LVQ
Description
This function simplifies training a supervised Learning Vector Quantizer Neural Network (LVQ NN), as compared to using the LVQs
module directly. Once the NN is trained, the function returns a matrix containing the codebook vector information. This matrix can then be used by LVQs_recall
to classify other data.
Usage
LVQs_train( train_data,
train_class,
iterations = 1000,
number_of_output_nodes_per_class = 1,
reward_coef = +0.2,
punish_coef = -0.2,
training_order = "reorder_once",
initialization_method = "sample",
recall_train_data = FALSE)
Arguments
train_data |
training data, numeric matrix (2d, cases in rows, variables in columns). |
train_class |
vector of integers or factor containing the desired class id for each training data case (row). Expected ids start from 1. |
iterations |
integer, number of training epochs, i.e. number of times the entire training data set will be presented to the NN during training. Maximum allowed is 10000. |
number_of_output_nodes_per_class |
integer, number of output nodes (and thus codebook vectors) to be used per class. A single value is expected, all classes are assigned this (same) number of output nodes. |
reward_coef |
coefficient used when a output node (and thus codebook vector) is rewarded (has been correctly selected when a training data vector is encoded) and is adjusted closer to the data. For more, see |
punish_coef |
coefficient used when a output node (and thus codebook vector) is punished (has been incorrectly selected when a training data vector is encoded) and is adjusted away from the data. For more, see |
training_order |
order by which the data set vectors will be presented to LVQs for encoding during each training iteration (epoch). Options are: |
initialization_method |
defines how the connections weights (codebook vectors) will be initialized. Options are: |
recall_train_data |
once training completes, recall the training data and show accuracy and confusion matrix. |
Details
This is a wrapper function which internally employs an instance of the LVQs
module. For more details, see LVQs
.
Value
A numeric matrix containing the codebook vector coordinates, the number of times each vector was rewarded during encoding (second from last column named 'Rewards'
, ) and the class it corresponds to (last column, named 'Class'
). This matrix can be used by LVQs_recall
function to classify other data.
Author(s)
Vasilis N. Nikolaidis <vnnikolaidis@gmail.com>
References
Simpson, P. K. (1991). Artificial neural systems: Foundations, paradigms, applications, and implementations. New York: Pergamon Press. p.88.
See Also
Examples
# start with the well-know iris dataset:
DATA <- iris[,1:4]
CLASS <- as.factor(iris$Species)
# Randomly split the data into training and testing sets:
indices <- sample(1:nrow(DATA), size = .5 * nrow(DATA))
train_data <- DATA[indices, ]
train_class <- CLASS[indices]
test_data <- DATA[-indices, ]
test_class <- CLASS[-indices]
# train LVQ using train data and class:
cv <- LVQs_train(train_data,
train_class,
number_of_output_nodes_per_class = 4)
# recall (classify) test data:
cl <- LVQs_recall(cv, test_data)
# Compare known and returned test data classifications:
print(table(test_class, cl))