Community
cancel
Showing results for 
Search instead for 
Did you mean: 
alvarez__javier
Beginner
132 Views

PyDAAL SVM classification

Hello,

I have been trying to do some SVM classification with PyDAAL, but I haven't been able to get past the most simple example. This the code that I am executing:

from sklearn.datasets import load_digits
import numpy as np
from daal.algorithms.svm import training
from daal.algorithms import kernel_function, classifier
from daal.data_management import HomogenNumericTable

data, labels = load_digits(2, True)
trainingData = HomogenNumericTable(data)
trainingLabels = HomogenNumericTable(labels[:, np.newaxis])

alg = training.Batch()
alg.parameter.kernel = kernel_function.linear.Batch()
alg.input.set(classifier.training.data, trainingData)
alg.input.set(classifier.training.labels, trainingLabels)
alg.compute()

and this is the error that I am getting:

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-49-294f650c8cc7> in <module>()
----> 1 alg.compute()

/opt/intel/intelpython2/lib/python2.7/site-packages/daal/algorithms/svm/training.pyc in compute(self)
    239 
    240     def compute(self):
--> 241         return _training23.Batch_Float64Boser_compute(self)
    242 Batch_Float64Boser_swigregister = _training23.Batch_Float64Boser_swigregister
    243 Batch_Float64Boser_swigregister(Batch_Float64Boser)

SystemError: Number of rows in numeric table is incorrect

Can anybody help me?

Thank you,

Javier

0 Kudos
2 Replies
Preethi_V_Intel
Employee
132 Views

The documentation states that the labels for a binary SVM classifier must be 1 and -1,while the labels in your classifier are 0,1. I changed the label 0 to -1 and got your script to work, you can find more details on this classifier here

from sklearn.datasets import load_digits
import numpy as np
from daal.algorithms.svm import training
from daal.algorithms import kernel_function, classifier
from daal.data_management import HomogenNumericTable

data, labels = load_digits(2, True)
labels[labels==0]=-1 # replacing 0 with -1
trainingData = HomogenNumericTable(data)
trainingLabels = HomogenNumericTable(labels[:, np.newaxis])

alg = training.Batch()
alg.parameter.kernel = kernel_function.linear.Batch()
alg.input.set(classifier.training.data, trainingData)
alg.input.set(classifier.training.labels, trainingLabels)
alg.compute()

There is a GitHub repository with interactive tutorials, helper functions on PyDaal that you can find here if you are interested.

 

alvarez__javier
Beginner
132 Views

Thank you Preethi, that worked.

Reply