import liblinear import pprint d1 = [ [(0, 1), (1, 1), (2,2) ] , [(0, .9), (1, 1), (2,2) ] ] d2 = [ [(0, - 1), (1, 1), (2,2) ] , [(0, - .9), (1, 1), (2,2) ] ] d3 = [ [(0, 0), (1, - 1), (2,2) ] , [(0, 0), (1, - 1.1), (2,2) ] ] print "version is", liblinear.version def indent(txt): lines = txt.split("\n") print "\n".join(" "+l for l in lines) def run(problem): print print 50*"-" print "run with problem" pprint.pprint(problem) clfr = liblinear.LinearSVM.train(problem, liblinear.L2LOSS_SVM_DUAL) print print "clfr.tostring() gives:" indent( clfr.tostring()) print "\nWeights:" for w in clfr.get_weights(): print " ", w print "\nBias:" for x in clfr.get_bias(): print " ", x run([d1,d2]) run([d1,d2, d3])