# 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))
Run the code above in your browser using DataLab