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 set_encoding_coefficients method of LVQs

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 set_encoding_coefficients method of LVQs

training_order

order by which the data set vectors will be presented to LVQs for encoding during each training iteration (epoch). Options are: 'original' (vectors are presented in the order in which they are stored, i.e. first row to last), 'reorder_once' (vectors are randomly reordered once, then presented in this same order in all iterations), and 'reorder' (vectors are randomly reordered before each iteration).

initialization_method

defines how the connections weights (codebook vectors) will be initialized. Options are: '0to1' (random values in [0 1] range, note: internal training data will also be scaled to the same range), 'means' codebook vectors will be the corresponding class's mean vector), 'first' (the first vector(s) of each class will be used as initial codebook vector(s), randomly re-selected if not enough are available), and 'sample' (randomly selected vectors of each class will be used as initial codebook vectors, with replacement if not enough are available).

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

LVQs_recall, LVQs.

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))

[Package nnlib2Rcpp version 0.2.8 Index]