Each of those selectedSeveral scikit-learn clustering algorithms can be fit using cosine distances in scikit-learn:
from sklearn.clustercollections import DBSCAN, MeanShift, OPTICS import defaultdict from sklearn.metricsdatasets import load_iris from sklearn.pairwisecluster import cosine_distancesDBSCAN, OPTICS # Define clusteringsample algorithmsdata algorithmsiris = [DBSCAN,load_iris() X MeanShift,= OPTICS]iris.data # PlaceholderList forclustering resultsalgorithms resultsalgorithms = dict.fromkeys((a.__name__[DBSCAN, forOPTICS] a# inMeanShift algorithms))does not use a metric # Fit each clustering algorithm and store results results = defaultdict(int) for algorithm in algorithms: results[algorithm] = algorithm(metric=cosine_distancesmetric='cosine').fit(X)