def classifier_multiclassocas_modular(num_vec=10, num_class=3, distance=15, width=2.1, C=1, epsilon=1e-5, seed=1):
    from shogun.Features import RealFeatures, MulticlassLabels
    from shogun.Classifier import MulticlassOCAS
    from shogun.Mathematics import Math_init_random

    # reproducible results
    random.seed(seed)
    Math_init_random(seed)

    # generate some training data where each class pair is linearly separable
    label_train = array([mod(x, num_class) for x in range(num_vec)], dtype="float64")
    label_test = array([mod(x, num_class) for x in range(num_vec)], dtype="float64")
    fm_train = array(random.randn(num_class, num_vec))
    fm_test = array(random.randn(num_class, num_vec))
    for i in range(len(label_train)):
        fm_train[label_train[i], i] += distance
        fm_test[label_test[i], i] += distance

    feats_train = RealFeatures(fm_train)
    feats_test = RealFeatures(fm_test)

    labels = MulticlassLabels(label_train)

    classifier = MulticlassOCAS(C, feats_train, labels)
    classifier.train()

    out = classifier.apply(feats_test).get_labels()
    # print label_test
    # print out
    return out, classifier
def classifier_multiclassocas_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_multiclass=label_traindat,width=2.1,C=1,epsilon=1e-5):
	from shogun.Features import RealFeatures, Labels
	from shogun.Classifier import MulticlassOCAS

	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)

	labels=Labels(label_train_multiclass)

	classifier = MulticlassOCAS(C,feats_train,labels)
	classifier.train()

	out = classifier.apply(feats_test).get_labels()
	return out
Exemplo n.º 3
0
def classifier_multiclassocas_modular(fm_train_real=traindat,
                                      fm_test_real=testdat,
                                      label_train_multiclass=label_traindat,
                                      width=2.1,
                                      C=1,
                                      epsilon=1e-5):
    from shogun.Features import RealFeatures, MulticlassLabels
    from shogun.Classifier import MulticlassOCAS

    feats_train = RealFeatures(fm_train_real)
    feats_test = RealFeatures(fm_test_real)

    labels = MulticlassLabels(label_train_multiclass)

    classifier = MulticlassOCAS(C, feats_train, labels)
    classifier.train()

    out = classifier.apply(feats_test).get_labels()
    return out
def classifier_multiclassocas_modular(num_vec=10,
                                      num_class=3,
                                      distance=15,
                                      width=2.1,
                                      C=1,
                                      epsilon=1e-5,
                                      seed=1):
    from shogun.Features import RealFeatures, MulticlassLabels
    from shogun.Classifier import MulticlassOCAS
    from shogun.Mathematics import Math_init_random

    # reproducible results
    random.seed(seed)
    Math_init_random(seed)

    # generate some training data where each class pair is linearly separable
    label_train = array([mod(x, num_class) for x in range(num_vec)],
                        dtype="float64")
    label_test = array([mod(x, num_class) for x in range(num_vec)],
                       dtype="float64")
    fm_train = array(random.randn(num_class, num_vec))
    fm_test = array(random.randn(num_class, num_vec))
    for i in range(len(label_train)):
        fm_train[label_train[i], i] += distance
        fm_test[label_test[i], i] += distance

    feats_train = RealFeatures(fm_train)
    feats_test = RealFeatures(fm_test)

    labels = MulticlassLabels(label_train)

    classifier = MulticlassOCAS(C, feats_train, labels)
    classifier.train()

    out = classifier.apply(feats_test).get_labels()
    #print label_test
    #print out
    return out, classifier