Issue 1:
Describe the workflow you want to enable

When verbose>0, the fitting is shown as a progress bar including the average time/pace and last fit attempted time.

Describe your proposed solution

Implement tqdm-like or keras-like (familiar to epoch tracking) progress bar such that the feature can be enabled through an argument of verbose. This proposal is under the assumption that the iteration is accessible like for loop.

Describe alternatives you've considered, if relevant

No response

Additional context

I've been using GridSearchCV and brute-forcing parameters (regarding algorithms, domain-knowledge agnostic) to find the best model parameters while leaving the machine unattended (disconnect from the cloud). But sometimes, the kernel might freeze without any indication. Even with verbose tracking, it's hard to skim through the log, especially among hundreds of fits to deduce that the process has been interrupted.

The issue expanded from a simple inquiry of #6021 .

Issue 2:
Describe the bug

The constant:sklearn.neighbors.VALID_METRICS['brute'] returns duplicate "cosine" keyword.

It seems harmless, but I think it should return a unique keyword list to avoid unnecessary confusion.

The constant is defined here:

scikit-learn/sklearn/neighbors/_base.py

Lines 40 to 69
in
691972a

VALID_METRICS = dict(

ball_tree=BallTree.valid_metrics,

kd_tree=KDTree.valid_metrics,

# The following list comes from the

# sklearn.metrics.pairwise doc string

brute=(

list(PAIRWISE_DISTANCE_FUNCTIONS.keys())

+ [

"braycurtis",

"canberra",

"chebyshev",

"correlation",

"cosine",

"dice",

"hamming",

"jaccard",

"kulsinski",

"mahalanobis",

"matching",

"minkowski",

"rogerstanimoto",

"russellrao",

"seuclidean",

"sokalmichener",

"sokalsneath",

"sqeuclidean",

"yule",

]

),

)

Removing cosine from the latter list looks OK, but I think using set().union is more robust.

brute=(
set(PAIRWISE_DISTANCE_FUNCTIONS.keys()).union([
"braycurtis",
"canberra",
"chebyshev",
"correlation",
"cosine",
"dice",
...
])
)

Steps/Code to Reproduce

Run the following codes on the colab.

!pip install scikit-learn -Uq

import sklearn.neighbors
brute_metrics = sorted(sklearn.neighbors.VALID_METRICS['brute'])
print(len(brute_metrics), len(set(brute_metrics)))
print(brute_metrics[5:7])

The result will be:

29 28
['cosine', 'cosine']

Expected Results

sklearn.neighbors.VALID_METRICS['brute'] returns unique keywords

Actual Results

import sklearn.neighbors
brute_metrics = sorted(sklearn.neighbors.VALID_METRICS['brute'])
assert len(brute_metrics) == len(set(brute_metrics)), "detect duplicates!"

Got:

---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
[<ipython-input-13-279d32fcf741>](https://localhost:8080/#) in <module>()
1 import sklearn.neighbors
2 brute_metrics = sorted(sklearn.neighbors.VALID_METRICS['brute'])
----> 3 assert len(brute_metrics) == len(set(brute_metrics)), "detect duplicates!"
4
5

AssertionError: detect duplicates!

Versions

System:
python: 3.7.12 (default, Jan 15 2022, 18:48:18) [GCC 7.5.0]
executable: /usr/bin/python3
machine: Linux-5.4.144+-x86_64-with-Ubuntu-18.04-bionic

Python dependencies:
pip: 21.1.3
setuptools: 57.4.0
sklearn: 1.0.2
numpy: 1.21.5
scipy: 1.4.1
Cython: 0.29.28
pandas: 1.3.5
matplotlib: 3.2.2
joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True