[英]How to assign sample_weights in sklearn.cluster DBSCAN?
I'm using DBSCAN to find clusters of pixel values of an RGB image. 我正在使用DBSCAN查找RGB图像的像素值的群集。
db = DBSCAN(eps=0.3, min_samples=10).fit(X)
where, X
is an N x 3
matrix. 其中,
X
是N x 3
矩阵。 Each row of X
contains RGB triplets. X
每一行都包含RGB三胞胎。
Now, I want to assign weights to pixel values as a function of distance from the center of the image. 现在,我想为像素值分配权重,该权重是距图像中心的距离的函数。 And this is the function I'm using:
这是我正在使用的功能:
score = 1 / (1 + math.exp(-a * distance)) # a = 0.001
I compute weight_matrix
filled with score
as above 我计算
weight_matrix
用上面的score
填充的weight_matrix
Next I did this: 接下来,我这样做:
db = DBSCAN(eps=0.3, min_samples=10).fit(X,y=None, sample_weight=weight_matrix)
where, length of the weight_matrix
array is equal to the number of rows in X
. 其中
weight_matrix
数组的长度等于X
的行数。
But I get the following error: 但是我收到以下错误:
TypeError: fit() got an unexpected keyword argument 'y'
So I tried doing it like this: 所以我尝试这样做:
db = DBSCAN(eps=0.3, min_samples=10).fit(X, sample_weight=weight_matrix)
Now I get this error: 现在我得到这个错误:
TypeError: fit() got an unexpected keyword argument 'sample_weight'
I think I'm passing the arguments incorrectly, but couldn't be sure. 我认为我传递的参数有误,但不能确定。 My scikit-learn version is 0.14.0.
我的scikit-learn版本是0.14.0。
It seems that you are using scikit-learn v <= 0.15, as this is the last version where DBSCAN had fit of form 似乎您正在使用scikit-learn v <= 0.15,因为这是DBSCAN具有适合形式的最后一个版本
fit(X)
since 0.16 it is 从0.16开始
fit(X, y=None, sample_weight=None)
Simply update your scikit-learn to 0.16 or 0.17.X 只需将scikit-learn更新为0.16或0.17.X
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.