【发布时间】:2021-12-15 19:50:09
【问题描述】:
正如您在图片中看到的,聚类似乎与提供的数据完全无关。 我有 34 个数据点。 这可能是什么原因?
用不同的组件拟合 K GMM:
def calculate_zones(self):
mini_data = []
for id, enter_x, enter_y, enter_time, exit_x, exit_y, exit_time in self.data:
mini_data.append([enter_x, enter_y])
mini_data.append([exit_x, exit_y])
K = range(2, 4)
for k in K:
# Set the model and its parameters
self.gms.append(
GaussianMixture(n_components=k, n_init=20, covariance_type='spherical', init_params='kmeans').fit(
mini_data))
根据 GMM 的结果屏蔽图像:
def display_zones(self):
video = cv2.VideoCapture(self.video_path)
if not video.isOpened():
print("Cannot open stream")
exit()
_, frame = video.read()
mask = []
colors = random_color(11)
for model in self.gms:
curr_mask = np.zeros_like(frame)
mask.append(curr_mask)
row_index = 0
for pixel_row in frame:
column_index = 0
for _ in pixel_row:
prediction = model.predict_proba([[row_index, column_index]])
best_proba = 0
counter = 0
for one_prediction in prediction[0]:
if one_prediction > prediction[0][best_proba]:
best_proba = counter
counter += 1
curr_mask[row_index][column_index] = colors[best_proba]
column_index += 1
row_index += 1
【问题讨论】:
标签: python machine-learning scikit-learn statistics gaussian