Python 输入维度错误

Python 输入维度错误,python,machine-learning,scipy,scikit-learn,Python,Machine Learning,Scipy,Scikit Learn,我正在尝试实现一个自定义rbf核函数。然而,我得到以下错误。我不知道为什么预期会有一定数量的数据点? 此代码行中出现错误: rbf_y = rbf_kernel.predict(X_test) 代码 错误: 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:

我正在尝试实现一个自定义rbf核函数。然而,我得到以下错误。我不知道为什么预期会有一定数量的数据点? 此代码行中出现错误:

rbf_y = rbf_kernel.predict(X_test)
代码

错误:

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)

自定义内核
内核(X,Y)
应该计算矩阵
X
和矩阵
Y
之间的相似性度量,并且输出应该是shape
[X.shape[0],Y.shape[0]
。内核函数忽略
Y
,并返回一个shape
[X.shape[0],X.shape[0]]]
矩阵,这将导致您看到的错误

要解决此问题,请实现一个内核函数,用于计算形状正确的内核矩阵。Scikit learn’s提供了一些简单的示例,说明了这可能是如何工作的


对于您的特定内核,您可以尝试使用
cdist(x,y)
代替
squareform(pdist(x))

您可以发布完整的堆栈跟踪吗。
myKernel(X_train, X_train).shape = (31488, 31488)