I created an SVM instance with a kernel function of my own definition. When I try to run cross validation on the created model, I get the following error:
ValueError: X should be a square kernel matrix
Traceback:
scores = cross_val_score(model, X, y, cv=10)
File "C:\Python27\lib\site-packages\scikit_learn-0.14.1-py2.7-win32.egg\sklearn\cross_validation.py", line 1152, in cross_val_score
for train, test in cv)
File "C:\Python27\lib\site-packages\scikit_learn-0.14.1-py2.7-win32.egg\sklearn\externals\joblib\parallel.py", line 517, in call
self.dispatch(function, args, kwargs)
File "C:\Python27\lib\site-packages\scikit_learn-0.14.1-py2.7-win32.egg\sklearn\externals\joblib\parallel.py", line 312, in dispatch
job = ImmediateApply(func, args, kwargs)
File "C:\Python27\lib\site-packages\scikit_learn-0.14.1-py2.7- win32.egg\sklearn\externals\joblib\parallel.py", line 136, in init
self.results = func(*args, **kwargs)
File "C:\Python27\lib\site-packages\scikit_learn-0.14.1-py2.7-win32.egg\sklearn\cross_validation.py", line 1047, in _cross_val_score
raise ValueError("X should be a square kernel matrix")
Here is my code:
def hist_intersection(x, y):
return np.sum(np.array([min(xi,yi) for xi,yi in zip(x,y)]))
model = svm.SVC(kernel = hist_intersection)
scores = cross_val_score(model, X, y, cv=10)