DistrictDataLabs / yellowbrick

Visual analysis and diagnostic tools to facilitate machine learning model selection.
http://www.scikit-yb.org/
Apache License 2.0
4.29k stars 559 forks source link

pairwise distance error for precomputed KElbowVisualizer #1282

Closed AnhVanGiang closed 2 years ago

AnhVanGiang commented 2 years ago

I don't know if I am doing this correctly or not but when KElbowVisualizer is used with a precomputed distance_metric, it gives an error ValueError: Precomputed metric requires shape (n_queries, n_indexed). Got ({X.shape[0]}, {X.shape[1]}) for 1 indexed. Example:

from sklearn.datasets import make_blobs
import gower

X, y = make_blobs(n_samples=1000, n_features=12, centers=8, random_state=42)
gx = gower.gower_matrix(X)

agglo_visualizer = KElbowVisualizer(
    AgglomerativeClustering(affinity="precomputed",
                            linkage="complete"), k=(1, 10), distance_metric="precomputed"
)

agglo_visualizer.fit(gx)