I tried to do this but am having errors. Seems like I need to use the
'metric_params' parameter but I cannot get it right. Here are some of the attempts I made:

{'metric': ['wminkowski'], 'metric_params':[{ 'w': [0.01, 0.1, 1, 10, 100], 'p': [1,2,3,4,5]}], 'n_neighbors': list(k_range), 'weights': weights, 'algorithm': algos, 'leaf_size': list(leaf_sizes) }

{'metric': ['wminkowski'], 'metric_params':[{ 'w': 0.01, 'p': 1}], 'n_neighbors': list(k_range), 'weights': weights, 'algorithm': algos, 'leaf_size': list(leaf_sizes) }

{'metric': ['wminkowski'], 'metric_params':[dict(w=0.01,p=1)], 'n_neighbors': list(k_range), 'weights': weights, 'algorithm': algos, 'leaf_size': list(leaf_sizes) }

The last two give me the following error:

Exception ignored in: 'sklearn.neighbors.dist_metrics.get_vec_ptr'
ValueError: Buffer has wrong number of dimensions (expected 1, got 0)

Can anyone see what I am doing wrong?


I can see *something* you're doing wrong. Firstly, your second and third examples produce identical Python objects.

But in metric_params, p should be an integer, w should be a 1-dimensional array. In your first example, both p and w will be 1d, and in your second and third, both are scalars. You want something like ... 'metric_params': [{'w': [0.01, 0.1, 1, 10, 100], 'p': 1}] ... except that those values for 'w' seem a bit strange for weights (are you sure you want wminkowski?). You can try multiple 'p' with 'metric_params': [{'w': weights, 'p': 1}, {'w': weights, 'p': 2}, {'w': weights, 'p': 3}, ...]