Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • bob.learn.libsvm bob.learn.libsvm
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • bobbob
  • bob.learn.libsvmbob.learn.libsvm
  • Issues
  • #6
Closed
Open
Issue created Nov 19, 2015 by André Anjos@andre.anjos💬Owner

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)
Assignee
Assign to
Time tracking