vendredi 5 juin 2020

Nearest Neighbors and Mahalanobis distance for new points

I would like to ask how can I use Mahalanobis distance for new data. The following codes show fitting to data and find its nearest neighbors. I want to find new data distances to the samples of data.

nbrs = NearestNeighbors(n_neighbors=n,metric ='mahalanobis',n_jobs =2,metric_params={'VI': np.cov(data.T)}).fit(data)

for i in range (0,l):
    nearest_dist, nearest_ind = nbrs.kneighbors(data)

The following figure may be more clear to explain my question. The right one works well and finds the nearest Mahalanobis distances and neighbors. However, the right one does not find the nearest data values (black points) to the grid points (for example the red one). How can I find a solution to this problem?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire