# The training data given with the "training" option may have class labels as
# its last dimension (so, if the training data is in CSV format, labels
# should be the last column). Alternately, the "labels" parameter may be
# used to specify a separate matrix of labels.
#
# All these options make it easy to train a perceptron, and then re-use that
# perceptron for later classification. The invocation below trains a
# perceptron on "training_data" with labels "training_labels", and saves the
# model to "perceptron_model".
if (FALSE) {
output <- perceptron(training=training_data, labels=training_labels)
perceptron_model <- output$output_model
}
# Then, this model can be re-used for classification on the test data
# "test_data". The example below does precisely that, saving the predicted
# classes to "predictions".
if (FALSE) {
output <- perceptron(input_model=perceptron_model, test=test_data)
predictions <- output$predictions
}
# Note that all of the options may be specified at once: predictions may be
# calculated right after training a model, and model training can occur even
# if an existing perceptron model is passed with the "input_model" parameter.
# However, note that the number of classes and the dimensionality of all
# data must match. So you cannot pass a perceptron model trained on 2
# classes and then re-train with a 4-class dataset. Similarly, attempting
# classification on a 3-dimensional dataset with a perceptron that has been
# trained on 8 dimensions will cause an error.
Run the code above in your browser using DataLab