경기도미래기술학교 AI개발자 부트캠프 37일차 - 클러스터링(Clustering) 공부하기.

2023. 6. 30. 10:28python

반응형

챗 GPT에 클러스터링이 어떤 곳에 활용되는지 물어보자.

 

 

대표적인 군집화 알고리즘으로는 K-Means, Mean Shift, Gaussian Mixture Model, DBScan이 있다.

 

import numpy as np
import matplotlib.pyplot as plt

def euclidean_distance(x1, y1, x2, y2):
    result = (((y1-x1)**2) + ((y2-x2)**2)) ** 0.5
    return result

n_classes = 4
n_data = 100

X, y = [], []

for class_idx in range(n_classes):
    centroid = np.random.uniform(low=-10, high=10, size=(2,))
    X_ = np.random.normal(loc=centroid, scale=1, size=(n_data, 2))
    y_ = class_idx * np.ones(n_data,)
    X.append(X_)
    y.append(y_)

X, y = np.vstack(X), np.concatenate(y)


colors = ['slategray', 'blueviolet', 'cyan', 'gold']
class_labels = np.unique(y)

fig, ax = plt.subplots(1, 1, figsize=(8, 8))

np.random.shuffle(X)

for i in range(400):
    ax.scatter(X[i, 0], X[i, 1], c='blue')

#랜덤점찍기.
for i in range(4):
    ax.scatter(X[i, 0], X[i, 1], c='red', s=200, marker='o')

plt.show()

이렇게 했는데 강사님이 나중에 계산할 때 불편하다고 다르게 해보라고 하셨다..

 

다시 해보자.

728x90