- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Preethi, that worked.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page