Math Problem Statement
下面实现一个项目。机械臂采摘万寿菊,目前的技术思路为首先使用相机垂直于花田正上方拍摄一张图片,基于YOLO模型获取每朵菊花的空间坐标点(目前均已实现,你不用管了)。现在使用DBSCAN聚类算法完成花朵的聚类,其中z坐标的优先级最高,请你在下面的代码上修改和完善。import numpy as np from sklearn.cluster import DBSCAN from sklearn import metrics from sklearn.datasets import make_moons from sklearn.preprocessing import StandardScaler import matplotlib.pyplot as plt
生成一些非球形的数据集
X, labels_true = make_moons(n_samples=300, noise=0.1, random_state=42)
由于DBSCAN对尺度敏感,我们先进行标准化
X = StandardScaler().fit_transform(X)
使用DBSCAN
eps:ε-邻域的大小
min_samples:形成密集区域所需的最小样本数(或总权重)。表达为样本数或样本数占总数的比例
db = DBSCAN(eps=0.3, min_samples=10).fit(X) core_samples_mask = np.zeros_like(db.labels_, dtype=bool) core_samples_mask[db.core_sample_indices_] = True labels = db.labels_
绘制结果
unique_labels = set(labels) colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))] for k, col in zip(unique_labels, colors): if k == -1: # 黑色用于噪声 col = [0, 0, 0, 1]
class_member_mask = (labels == k)
xy = X[class_member_mask & core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),
markeredgecolor='k', markersize=14)
xy = X[class_member_mask & ~core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),
markeredgecolor='k', markersize=6)
plt.title('Estimated number of clusters: %d' % len(unique_labels)) plt.show()
Solution
Ask a new question for Free
By Image
Drop file here or Click Here to upload
Math Problem Analysis
Mathematical Concepts
Machine Learning
Clustering
DBSCAN Algorithm
Three-dimensional Geometry
Formulas
-
Theorems
-
Suitable Grade Level
N/A
Related Recommendation
Black and White Dendrograms for Single-Link and Complete-Link Hierarchical Clustering
Perform Hierarchical Clustering Using Dendrograms: Step-by-Step Guide
K-means Clustering: Distance Between Points and Cluster Centers
K-Means Clustering: CGPA and Assessment Data Using Initial Seeds
Calculating Different Clustering Configurations for 18 Variables into 4 Clusters