def classifier_svmocas_modular(fm_train_real=traindat, fm_test_real=testdat, label_train_twoclass=label_traindat, C=0.9, epsilon=1e-5, num_threads=1): from shogun.Features import RealFeatures, SparseRealFeatures, Labels from shogun.Classifier import SVMOcas realfeat = RealFeatures(fm_train_real) feats_train = SparseRealFeatures() feats_train.obtain_from_simple(realfeat) realfeat = RealFeatures(fm_test_real) feats_test = SparseRealFeatures() feats_test.obtain_from_simple(realfeat) labels = Labels(label_train_twoclass) svm = SVMOcas(C, feats_train, labels) svm.set_epsilon(epsilon) svm.parallel.set_num_threads(num_threads) svm.set_bias_enabled(False) svm.train() svm.set_features(feats_test) svm.classify().get_labels() predictions = svm.classify() return predictions, svm, predictions.get_labels()
def svmocas(): print "SVMOcas" from shogun.Features import RealFeatures, SparseRealFeatures, Labels from shogun.Classifier import SVMOcas realfeat = RealFeatures(fm_train_real) feats_train = SparseRealFeatures() feats_train.obtain_from_simple(realfeat) realfeat = RealFeatures(fm_test_real) feats_test = SparseRealFeatures() feats_test.obtain_from_simple(realfeat) C = 0.9 epsilon = 1e-5 num_threads = 1 labels = Labels(label_train_twoclass) svm = SVMOcas(C, feats_train, labels) svm.set_epsilon(epsilon) svm.parallel.set_num_threads(num_threads) svm.set_bias_enabled(False) svm.train() svm.set_features(feats_test) svm.classify().get_labels()
def classify(true_labels): num_feats = 2 num_vec = true_labels.get_num_labels() data_train = numpy.concatenate( (numpy.random.randn(num_feats, num_vec / 2) - 1, numpy.random.randn(num_feats, num_vec / 2) + 1), axis=1) realfeat = RealFeatures(data_train) feats_train = SparseRealFeatures() feats_train.obtain_from_simple(realfeat) C = 3. svm = SVMOcas(C, feats_train, true_labels) svm.train() data_test = numpy.concatenate( (numpy.random.randn(num_feats, num_vec / 2) - 1, numpy.random.randn(num_feats, num_vec / 2) + 1), axis=1) realfeat = RealFeatures(data_test) feats_test = SparseRealFeatures() feats_test.obtain_from_simple(realfeat) svm.set_features(feats_test) return numpy.array(svm.classify().get_labels())
def classify (true_labels): num_feats=2 num_vec=true_labels.get_num_labels() data_train=numpy.concatenate( (numpy.random.randn(num_feats, num_vec/2)-1, numpy.random.randn(num_feats, num_vec/2)+1), axis=1) realfeat=RealFeatures(data_train) feats_train=SparseRealFeatures() feats_train.obtain_from_simple(realfeat) C=3. svm=SVMOcas(C, feats_train, true_labels) svm.train() data_test=numpy.concatenate( (numpy.random.randn(num_feats, num_vec/2)-1, numpy.random.randn(num_feats, num_vec/2)+1), axis=1) realfeat=RealFeatures(data_test) feats_test=SparseRealFeatures() feats_test.obtain_from_simple(realfeat) svm.set_features(feats_test) return numpy.array(svm.classify().get_labels())
def classifier_svmocas_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,C=0.9,epsilon=1e-5,num_threads=1): from shogun.Features import RealFeatures, SparseRealFeatures, Labels from shogun.Classifier import SVMOcas realfeat=RealFeatures(fm_train_real) feats_train=SparseRealFeatures() feats_train.obtain_from_simple(realfeat) realfeat=RealFeatures(fm_test_real) feats_test=SparseRealFeatures() feats_test.obtain_from_simple(realfeat) labels=Labels(label_train_twoclass) svm=SVMOcas(C, feats_train, labels) svm.set_epsilon(epsilon) svm.parallel.set_num_threads(num_threads) svm.set_bias_enabled(False) svm.train() svm.set_features(feats_test) svm.classify().get_labels() predictions = svm.classify() return predictions, svm, predictions.get_labels()