pynndescent icon indicating copy to clipboard operation
pynndescent copied to clipboard

Can't pass parameters to weighted_minkowski distance metric

Open Stevod opened this issue 2 years ago • 3 comments

When I run this code, index = NNdescent(data = data, metric = 'weighted_minkowski', metric_kwds={'p':1} ) I get an error of no match with getitem. How can I pass this?

Also, I need to pass an array of weights to weight the metric. How can I pass those? By convetring to a dict?

Thanks, David

Stevod avatar Jun 30 '22 13:06 Stevod

That should work; I'll see if I can look into it.

lmcinnes avatar Jun 30 '22 16:06 lmcinnes

Many thanks, as the ability to use different/custom metrics is why I selected the pynndescent package in the first place.

Also, I cannot pass the additional 'w' metric into a custom metric using metric_kwds={'w' : w.to_dict()} as I expected. Could you provide an example of how to do that as well for a custom function.

Much appreciated. David

Stevod avatar Jul 01 '22 10:07 Stevod

Due to how things have to get handled by numba, in practice you need to pass all the required arguments in the correct order to the distance function. That means for weighted minkowski you'll have to pass w and p (if you just want to use p you cna always use minkowski instead). To pass w you'll need to pass a vector of length giving the weight for each coordinate.

lmcinnes avatar Jul 04 '22 14:07 lmcinnes