-
-
Save sujeong000/b3beffb20ee0072cf0ea6e78c19908a4 to your computer and use it in GitHub Desktop.
DBSCAN을 사용하여 시선 데이터 클러스터링
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.cluster import DBSCAN | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as patches | |
import cv2 | |
# 총 200개의 좌표 생성 | |
number_of_points = [20, 10, 20, 10, 100, 40] | |
x_ranges = [(0.3, 0.7), (0.4, 0.5), (0.2, 0.5), (0.9, 1.0), (0.7, 0.8), (0.2, 0.3)] | |
y_ranges = [(0.3, 0.9), (0.2, 0.5), (0.2, 0.6), (0.1, 0.2), (0.2, 0.7), (0.1, 0.3)] | |
points = [] | |
for i in range(6): | |
for j in range(number_of_points[i]): | |
x = np.random.uniform(low=x_ranges[i][0], high=x_ranges[i][1]) | |
y = np.random.uniform(low=y_ranges[i][0], high=y_ranges[i][1]) | |
points.append((x, y)) | |
# 노이즈 추가 | |
noise = np.random.uniform(low=0.0, high=0.15, size=(200, 2)) | |
# 시선 더미 데이터 | |
gaze_data = points + noise | |
print(gaze_data) | |
# DBSCAN 알고리즘 사용하여 시선데이터 클러스터링 | |
dbscan = DBSCAN(eps=0.1, min_samples=20) | |
labels = dbscan.fit_predict(gaze_data) | |
# 클러스터 개수 출력 | |
n_clusters = len(set(labels)) - (1 if -1 in labels else 0) | |
print(f"Number of clusters found: {n_clusters}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment