Hi,

While playing with GridSearchCV and an SVM with precomputed kernel
I came across the issue that cross-validation seems not to slice
the precomputed kernel in the proper way during fit(). Here is a
minimal example:
---

import numpy as np
from sklearn.grid_search import GridSearchCV
from sklearn.svm import SVC

if __name__=='__main__':

     kernel = np.eye(10)
     y = np.array([0]*5+[1]*5)
     clf = GridSearchCV(SVC(kernel='precomputed'), cv=5, param_grid={'C':[1.0]})
     clf.fit(kernel, y)
---

which returns
---
/usr/lib/pymodules/python2.6/sklearn/svm/classes.py:184: FutureWarning: SVM: 
scale_C will be True by default in scikit-learn 0.11
   cache_size, scale_C)
Traceback (most recent call last):
   File "test_precomputed_cv.py", line 10, in<module>
     clf.fit(kernel, y)
   File "/usr/lib/pymodules/python2.6/sklearn/grid_search.py", line 321, in fit
     for clf_params in grid for train, test in cv)
   File "/usr/lib/pymodules/python2.6/joblib/parallel.py", line 473, in __call__
     self.dispatch(function, args, kwargs)
   File "/usr/lib/pymodules/python2.6/joblib/parallel.py", line 296, in dispatch
     job = ImmediateApply(func, args, kwargs)
   File "/usr/lib/pymodules/python2.6/joblib/parallel.py", line 124, in __init__
     self.results = func(*args, **kwargs)
   File "/usr/lib/pymodules/python2.6/sklearn/grid_search.py", line 102, in 
fit_grid_point
     clf.fit(X_train, y_train, **fit_params)
   File "/usr/lib/pymodules/python2.6/sklearn/svm/base.py", line 197, in fit
     raise ValueError("X.shape[0] should be equal to X.shape[1]")
ValueError: X.shape[0] should be equal to X.shape[1]
---

Is there a ready-made solution to this?

Best,

Emanuele



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to