View source: R/LVQs_helper_functions.R
LVQs_train | R Documentation |
This function simplifies using a Supervised Learning Vector Quantizer Neural Network on data (as compared to using the LVQs
module directly). It trains a supervised Learning Vector Quantizer Neural Network (LVQs
). Once the NN is trained, the function returns a matrix containing codebook vectors and related information. This matrix can then be used by LVQs_recall
to classify data.
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,
initial_codebook_vectors = NULL
)
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. Number of classes is assumed to be equal to the maximum class id found here. |
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. |
initial_codebook_vectors |
a matrix of codebook vectors to be used as initial weight values when |
This is a wrapper function which internally employs an instance of the LVQs
module. For more details, see LVQs
.
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.
Vasilis N. Nikolaidis <vnnikolaidis@gmail.com>
Simpson, P. K. (1991). Artificial neural systems: Foundations, paradigms, applications, and implementations. New York: Pergamon Press. p.88.
LVQs_recall
, LVQs
.
# 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:
cvi <- LVQs_train(train_data,
train_class,
number_of_output_nodes_per_class = 4)
# recall (classify) test data:
cl <- LVQs_recall(cvi, test_data)
# Compare known and returned test data classifications:
print(table(test_class, cl))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.