Error using NU_SVC machine
Created by: acostapazo
I got the following error using a trainer with machine_type=='NU_SVC'
RuntimeError: 1D input' array should have 0 elements matching
bob.learn.libsvm.Machine' input size, not 3 elements
I tried to reproduce this behaviour using the following code. Here we can observe that with random data (100 per each classes) all works in a expected way, but if I use different data, the machine that I get from the trainer seams corrupted. Take note that the machine shape is very unexpected in the second test and this produces the error.
import os
import numpy
numpy.random.seed(10)
import bob.learn.libsvm
def svm_predict(svm_machine, data):
labels = [svm_machine.predict_class_and_scores(x)[0][0] for x in data]
return numpy.array(labels)
def train_and_test(train_class1,train_class2,test):
svm_trainer = bob.learn.libsvm.Trainer(machine_type='NU_SVC')
svm_machine = svm_trainer.train([train_class1,train_class2])
print svm_machine.shape
pred_test = svm_predict(svm_machine,test)
return pred_test
print 'Test 1 ************************************************************'
train_class1 = 0.4 * numpy.random.randn(100, 3).astype(numpy.float64)
train_class2 = 0.6 * numpy.random.randn(100, 3).astype(numpy.float64)
test = 0.4 * numpy.random.randn(20, 3).astype(numpy.float64)
pred_test = train_and_test(train_class1,train_class2,test)
print 'Test 2 (less data) *************************************************'
train_class1 = 0.4 * numpy.random.randn(60, 3).astype(numpy.float64)
train_class2 = 0.6 * numpy.random.randn(290, 3).astype(numpy.float64)
test = 0.4 * numpy.random.randn(20, 3).astype(numpy.float64)
pred_test = train_and_test(train_class1,train_class2,test)