sesac ai 과정/DL

[DATA_SET]BLOBS

standingR 2023. 11. 19. 17:17

 

 

 

 

 


INDEX

0. [DATA_SET]BLOBS

01.  CODE :

1-1 * Cluster

 


0. [DATA_SET]BLOBS

 

 

 

 

 

sklearn.datasets. make_blobs ( n_samples = 100 , n_features = 2 , * , center = None , Cluster_std = 1.0 , 
center_box = (-10.0, 10.0) , shuffle = True , random_state = None , return_centers = False )

https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_blobs.html

 

sklearn.datasets.make_blobs

Examples using sklearn.datasets.make_blobs: Release Highlights for scikit-learn 1.1 Release Highlights for scikit-learn 0.23 Probability Calibration for 3-class classification Probability calibrati...

scikit-learn.org

 

`make_blobs` 함수는 Scikit-learn 라이브러리에서 제공하는 함수 중 하나로, 가상의 *Cluster (클러스터)  를 생성하는 데 사용된다..

주어진 매개변수(parameters )를 활용하여 여러 가상의 클러스터를 형성하고, 이를 통해 데이터셋을 만들어냅니다.

 

 


parameters 설명

매개변수 설명 기본값
n_samples 클러스터당 샘플 또는 전체 포인트 100
n_features 샘플의 특징 2
centers 생성할 중심의 또는 고정된 중심 위치 None
cluster_std 클러스터의 표준 편차 1.0
center_box 클러스터 중심의 바운딩 박스 (-10.0, 10.0)
shuffle 샘플을 섞을지 여부 True
random_state 데이터셋 생성을 위한 난수 생성 None
return_centers 클러스터의 중심 반환 여부 False

 

 

Return

  • X: (n_samples, n_features) 모양의 ndarray. 생성된 샘플.
  • y: (n_samples,) 모양의 ndarray. 각 샘플의 클러스터 소속 정수 레이블.
  • centers: (n_centers, n_features) 모양의 ndarray. 클러스터의 중심. return_centers True 반환됨.

 

 

이 함수는 주로 클러스터링 알고리즘을 시험하거나 시각화하기 위한 가상 데이터셋을 만드는 데 사용됩니다. 또한, 지도 학습 알고리즘의 성능을 평가하고자 할 때도 사용될 수 있습니다. 이 함수를 이용하여 간단한 형태의 가상 데이터를 생성하고, 이를 통해 머신러닝 모델을 실험하고 테스트하는 데 유용하게 활용할 수 있습니다.

 


01.  CODE :

 

# pos 양성(positive) 클래스를 의미하고, neg 음성(negative) 클래스를 나타냅니다

 

# sklearn에 있는 SampleData 생성
# 앞으로는 혼동을 막기위해 학습 데이터 = Sample이라고 명시

from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt

# 샘플의 갯수 설정
n_samples = 100
# 시각화를 위한 작업으로 X = input sampe y = out sampe로 subplots 상에 그려짐
# 특징으로는 cluster_std와 features 가 있다.

X, y = make_blobs(n_samples=n_samples, centers=2,
                  n_features=2, cluster_std=0.5)

# subplots을 출력할 도화지인 fig, 실제 출력되는 그래프인 subplots 생성
fig, ax = plt.subplots(figsize=(10, 10))

"""pos는 양성(positive) 클래스를 의미하고, neg는 음성(negative) 클래스를 나타냅니다
이 예시에서는 y 배열에서 클래스 레이블이 1인 경우를 양성 클래스로, 클래스 레이블이 0인 경우를 음성 클래스로 분류하고 있다. 
그리고 각 클래스의 데이터 포인트를 시각화할 때 X_pos와 X_neg로 구분하여 사용하고 있다.
"""
X_pos, X_neg = X[y == 1], X[y == 0]
ax.scatter(X_pos[:, 0], X_pos[:, 1],color='blue')
ax.scatter(X_neg[:, 0], X_neg[:, 1], color='red')

ax.tick_params(labelsize=15)
plt.show()

 

 

 


* 1-1 . Cluster

 

 

은하의 군집은 대표적인 cluster의 예시이다 - 출처 :https://viewspace.org/interactives/unveiling_invisible_universe/dark_matter/bullet_cluster

 

 

dic _

ENG : a group of similar things that are close together, sometimes surrounding something:
 
KR : 군체(群體), 집속체, 무리, 밀접해있는 다수의 무언가를 총칭

 

 


실제 사용되는 예시

 

클러스터 분석 : 

https://www.qualtrics.com/experience-management/research/cluster-analysis/