我想使用高斯过程实现二进制分类模型。根据官方文档,我的代码如下。
X 有 2048 个特征,Y 为 0 或 1。优化模型后,我试图评估性能。
然而,该predict_y
方法产生了一个奇怪的结果。预期pred
应该具有类似 (n_test_samples, 2) 的形状,它表示属于 0 类和 1 类的概率。但我得到的结果是 (n_test_samples, n_training_samples)。
出了什么问题?
def model(X,Y):
'''
X: (n_training_samples, n_features) , my example is (n, 2048)
Y: (n_training_samples,) , binary classification
'''
m = gpflow.models.VGP(
(X, Y), likelihood=gpflow.likelihoods.Bernoulli(), kernel=gpflow.kernels.SquaredExponential()
)
opt = gpflow.optimizers.Scipy()
opt.minimize(m.training_loss, variables=m.trainable_variables)
return m
def evaluate(model,X,Y,accuracy, MCC, Kappa):
'''
X: (n_test_samples, n_features) , my example is (n, 2048)
Y: (n_test_samples,) , binary classification
'''
pred,_ = model.predict_y(X)
print('pred.shape is {}'.format(pred)) # I got wired result (num of test samples <X.shape[0]>, num of training samples)
accuracy += [accuracy_score(Y, pred)]
MCC += [matthews_corrcoef(Y, pred)]
Kappa += [cohen_kappa_score(Y, pred)]
return accuracy, MCC, Kappa