我转载了您的代码,但确实收到了您的错误。 我在这里解释得更好:
他具有一个vectorized_text变量( np.stack ),该变量模拟一个“热编码”功能集(仅包含0和1)。 在DBSCAN模型中,他使用custom_metric函数来计算距离。 可以预期的是,在运行模型时,自定义指标函数将观测对按原样作为参数对:一个热编码值,但是当在距离函数中打印这些值时,仅照原样取,正如他在问题中所描述的,另一个似乎是一列实际价值:
x = [0.5 0.5 0.5 ... 0.5 0.5] y = [0. 0. 0. 1. 0. 0. ... 1. 0.]
无论如何,当我将列表传递给fit参数时,该函数将按原样获取值:
from sklearn.cluster import KMeans, DBSCAN, MeanShift
x = [1, 0, 1]
y = [0, 0, 1]
feature_set = [x*5]*5
def distance(x, y):
# Printing here the values. Should be 0s and 1s
print(x, y)
match_count = 0.
for xi, yi in zip(x, y):
if float(xi) == 1. and xi == yi:
match_count += 1
return match_count
def custom_metric(x, y):
# x, y are two vectors