Libsvm python error -
i'm trying figure out proper format of python list given input svm_problem function in python. got following program web, stackoverflow.
i have following:
from svm import * x=[ [1,0,1],[-1,0,-1],[1,0,0]] #x=[ [1,0,1],[-1,0,-1]] prob = svm_problem( [1,-1],x ) param = svm_parameter(kernel_type = linear, c = 10) m = svm_model(prob, param) print m.predict([ 1,1, 1]) it raises assertion error, says assert failed: assert len(x)==len(y).
but if x=[ [1,0,1],[-1,0,-1]], program works perfectly. not supposed give train-data problem of length more 2?
also don't understand in x=[[1,0,1],[-1,0,-1]] label , data?
any highly appreciated.
svm_problem() takes 2 parameters: first parameter of vector of labels, , second matrix of features. assertion error because specifying 2 labels, [1, -1], first parameter in call svm_problem.
example:
y = [1,-1,1,1] x = [[1,0,1], [-1,0,-1], [1,2,3], [4,5,6]] prob = svm_problem(y, x)
Comments
Post a Comment