import multiprocessing import multiprocessing.pool import nose.tools as ntools import numpy from smqtk.algorithms.classifier.libsvm import LibSvmClassifier from smqtk.representation import \ ClassificationElementFactory, \ DescriptorElementFactory from smqtk.representation.classification_element.memory import \ MemoryClassificationElement from smqtk.representation.descriptor_element.local_elements import \ DescriptorMemoryElement if LibSvmClassifier.is_usable(): class TestLibSvmClassifier (unittest.TestCase): def tearDown(self): # Clear MemoryElement content DescriptorMemoryElement.MEMORY_CACHE = {} def test_simple_classification(self): """ Test libSVM classification functionality using random constructed data, training the y=0.5 split """ DIM = 2 N = 1000 POS_LABEL = 'positive'
import multiprocessing import multiprocessing.pool import nose.tools as ntools import numpy from smqtk.algorithms.classifier import get_classifier_impls from smqtk.algorithms.classifier.libsvm import LibSvmClassifier from smqtk.representation import \ ClassificationElementFactory, \ DescriptorElementFactory from smqtk.representation.classification_element.memory import \ MemoryClassificationElement from smqtk.representation.descriptor_element.local_elements import \ DescriptorMemoryElement if LibSvmClassifier.is_usable(): class TestLibSvmClassifier(unittest.TestCase): def test_impl_findable(self): ntools.assert_in(LibSvmClassifier.__name__, get_classifier_impls()) def test_no_save_model_pickle(self): # Test model preservation across pickling even without model cache # file paths set. classifier = LibSvmClassifier( train_params={ '-t': 0, # linear kernel '-b': 1, # enable probability estimates '-c': 2, # SVM-C parameter C '-q': '', # quite mode },
import six from six.moves import cPickle, zip from smqtk.algorithms.classifier import Classifier from smqtk.algorithms.classifier.libsvm import LibSvmClassifier from smqtk.representation import \ ClassificationElementFactory, \ DescriptorElementFactory from smqtk.representation.classification_element.memory import \ MemoryClassificationElement from smqtk.representation.descriptor_element.local_elements import \ DescriptorMemoryElement from smqtk.utils.configuration import configuration_test_helper @pytest.mark.skipif(not LibSvmClassifier.is_usable(), reason="LibSvmClassifier does not report as usable.") class TestLibSvmClassifier (unittest.TestCase): def test_impl_findable(self): self.assertIn(LibSvmClassifier, Classifier.get_impls()) @mock.patch('smqtk.algorithms.classifier.libsvm.LibSvmClassifier' '._reload_model') def test_configuration(self, m_inst_load_model): """ Test configuration handling for this implementation. Mocking out model loading when given URIs if they happen to point to something. """ ex_model_uri = 'some model uri'