Primal SVM




Primal SVM implementation in python

This project is python port of Matlab Primal SVM - fast linear Primal SVM implementation by Olivier Chapelle

The main advantage is that it can handle realy big datasets eficiently in terms of seconds rather than days.

There are two solvers implemented:

  • Newton method solver - Newton solver is better suited for problems with large number of examples (>1M) but small dimension (less than 1000)
  • Conjugate Gradient solver - better for large and sparse problems

How to use

The api is very simple, if you work with scikit-leran you won't have any trouble

mnist = fetch_mldata('MNIST original', data_home='./')

# data field is 70k x 784 array, each row represents pixels from 28x28=784 image
images =
targets =

psvm = lsvm.PrimalSVM(l2reg=0.1)
start_time =
print('Start learning at {}'.format(str(start_time))), y_train)
end_time = 
print('Stop learning {}'.format(str(end_time)))
elapsed_time= end_time - start_time
print('Elapsed learning {}'.format(str(elapsed_time)))


Project containse two simple examples:

  • iris dataset classification
  • mnist handwritten image classification



  • [2017-06-05 09:53:15] v0.1.3: Update Readme, change image internals.

[2016-5-4 22:0] v0.1.2 - Update readme, add github reference [2016-5-4 21:59] v0.1.1 - first version, implemented only newton solver