0

以下代码返回错误:

import numpy as np
from sklearn.datasets import make_classification
from sklearn.neighbors import NearestNeighbors
X, y = make_classification()
nn = NearestNeighbors(algorithm='brute', 
                               metric='mahalanobis', 
                               metric_params={'V': np.cov(X, rowvar= False)})

nn.fit(X).kneighbors(X[:1, :]) 

返回以下错误:

/usr/local/lib/python3.7/dist-packages/sklearn/metrics/pairwise.py in _precompute_metric_params(X, Y, metric, **kwds)
   1545         else:
   1546             raise ValueError(
-> 1547                 "The 'VI' parameter is required for the mahalanobis metric "
   1548                 "when Y is passed."
   1549             )

ValueError: The 'VI' parameter is required for the mahalanobis metric when Y is passed.

我不确定错误消息的含义,因为我没有在任何地方传递 Y。此外,如果我在最后一行更改X[:1,:]X,则代码运行良好,但出于速度原因,我不想在整个输入数组上运行它。

4

0 回答 0