【发布时间】:2017-08-30 11:48:21
【问题描述】:
我正在尝试实现自定义 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)
【问题讨论】:
-
能否请您发布完整的堆栈跟踪。
标签: python machine-learning scipy scikit-learn