def f1_same_duplicates_score(x, y):
"""
Given cluster labels x and y, compute the f1 score
that the same elements are marked as duplicates
"""
import warnings
from sklearn.metrics import f1_score
if x.shape != y.shape:
raise ValueError
x_dup = _dbscan_unique2noisy(x)
x_dup[x_dup > -1] = 1 # duplicates
x_dup[x_dup == -1] = 0 # not duplicates
y_dup = _dbscan_unique2noisy(y)
y_dup[y_dup > -1] = 1 # duplicates
y_dup[y_dup == -1] = 0 # not duplicates
x_dup = np.abs(x_dup)
y_dup = np.abs(y_dup)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UndefinedMetricWarning)
score = f1_score(x_dup, y_dup)
return score
评论列表
文章目录