From 0f2fb4e49f3a4b41ba8f34bbddf2a270f30eb753 Mon Sep 17 00:00:00 2001 From: Artur Costa Pazo Date: Thu, 12 Nov 2015 17:04:46 +0100 Subject: [PATCH] Added patch for OC-SVM documentation --- doc/guide.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/guide.rst b/doc/guide.rst index 99c4394..838e05e 100644 --- a/doc/guide.rst +++ b/doc/guide.rst @@ -152,6 +152,40 @@ instead, this can be set before calling the >>> trainer.kernel_type = 'LINEAR' +One Class SVM +============= + +On the other hand, the package allows you to train a One Class Support Vector Machine. For training this kind of classifier take into account the following example. + +.. doctest:: + :options: +NORMALIZE_WHITESPACE + + >>> pos = 0.4 * numpy.random.randn(100, 2).astype(numpy.float64) + >>> data = [pos] + >>> print(data) # doctest: +SKIP + + +As the above example, an SVM [1]_ for one class problem can be trained easily using the +:py:class:`bob.learn.libsvm.Trainer` class and selecting the appropiete machine_type (ONE_CLASS). + +.. doctest:: + :options: +NORMALIZE_WHITESPACE + + >>> trainer = bob.learn.libsvm.Trainer(machine_type='ONE_CLASS') + >>> machine = trainer.train(data) + +Then, as explained before, a :py:class:`bob.learn.libsvm.Machine` can be used for classify the new entries. + +.. doctest:: + :options: +NORMALIZE_WHITESPACE + + >>> test = 0.4 * numpy.random.randn(20, 2).astype(numpy.float64) + >>> outliers = numpy.random.uniform(low=-4, high=4, size=(20, 2)).astype(numpy.float64) + >>> predicted_label_test = machine(test) + >>> predicted_label_outliers = machine(outliers) + >>> print(predicted_label) + >>> print(predicted_label) + Acknowledgements ---------------- -- 2.21.0