0
我正在尝试实现自定义rbf内核函数。但是,我收到以下错误。我不确定为什么需要一定数量的数据点?发生在这行代码 错误:输入维度错误
rbf_y = rbf_kernel.predict(X_test)
代码
def myKernel(x,y):
pairwise_dists = squareform(pdist(x, 'euclidean'))
K = scip.exp(-pairwise_dists ** 2/.08 ** 2)
return K
rbf_kernel = svm.SVC(kernel=myKernel, C=1).fit(X_train, Y_train.ravel())
rbf_y = rbf_kernel.predict(X_test)
rbf_accuracy = accuracy_score(Y_test, rbf_y)
错误:
ValueError: X.shape[1] = 15510 should be equal to 31488, the number of samples at training time
数据式样
X_train shape: (31488, 128)
X_test shape: (15510, 128)
Y_train shape: (31488, 1)
Y_test shape: (15510, 1)
返回从内核
形状myKernel(X_train, X_train).shape = (31488, 31488)
你可以请发布完整的堆栈跟踪。 –