Infer.NET user guide : Learners : Bayes Point Machine classifiers : The Learner API
Creation & serialization
Creating a Bayes Point Machine classifier
Once you have an instance of a mapping, creating a Bayes Point Machine classifier is as easy as calling one of the following two factory methods, depending on the type of classification problem:
Moreover, there are two versions for both methods, one which takes as input a mapping to the native data format (an implementation of IBayesPointMachineClassifierMapping) and one which takes as input a mapping to the standard data format (an implementation of IClassifierMapping). The factory methods return classifiers of type IBayesPointMachineClassifier, providing appropriate settings and means for training and prediction.
For instance, let's imagine we have implemented a mapping from some SQL database to the native format of the Bayes Point Machine classifier, called SqlNativeMapping. To create a classifier for a multi-class problem, we then simply write
Creating a Bayes Point Machine classifier is a lightweight operation - no data are accessed and no computations are performed.
Serialization is achieved through the Save extension method on the ILearner interface. There are two overloads of this method - one that takes in a file, and one that takes in a stream and a formatter. Both trained and untrained classifiers can be serialized (and deserialized).
To save a Bayes Point Machine classifier to file, for instance, we write
This serializes the parameters of the classifier and the user-defined mapping. It does not serialize any training data nor any attached event handler.
By calling one of the static Load methods of BayesPointMachineClassifier, it is possible to load a previously serialized classifier. Just like the Save method, Load can deserialize a classifier from a file or a stream (and a formatter). Here is how to load a classifier from a file:
The generic types that this method requires are
When a classifier is deserialized the generic parameters have to exactly match the ones used to serialize the classifier. Also, during deserialization a version check will be performed. Should the version of the serialized learner not match the version of the target learner, an exception will be thrown.
Then, for convenience, a number of methods exist which are more specific than Load, and which decrease the number of generic types that need to be specified. There is, for instance,
which equally deserializes the previously saved multi-class Bayes Point Machine classifier from file.