我正在尝试寻找 DBSCAN 的最佳 eps 值。我设置min_samples为 24,因为我有 2 * 12 个特征传入x_set,但出现以下错误:ValueError: Number of labels is 1. Valid values are 2 to n_samples - 1 (inclusive)我知道需要silhouette_score超过 1 个集群标签。基于类似的错误,这可能会导致此错误。我该如何解决这个问题?x_set包含以下数据:x_set = [6.67933536e+00 1.65097236e+00 1.24573705e+00 1.01693195e+00 9.28128921e-01 7.82497904e-01 5.98319768e-01 1.13439548e-01 9.05382510e-04 5.42710767e-04 2.87522799e-04 1.90924073e-04]def best_eps(x_set): X = x_set range_eps = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] for i in range_eps: print("eps value is: "+str(i)) db = DBSCAN(eps=i, min_samples=24, metric='euclidean').fit(X) core_samples_mask = np.zeros_like(db.labels_, dtype=bool) core_samples_mask[db.core_sample_indices_] = True labels = db.labels_ print(set(labels)) silhouette_avg = silhouette_score(X, labels) print("For eps value ="+str(i), labels, "The average silhouette_score is :", silhouette_avg) return
添加回答
举报
0/150
提交
取消