<jupyter_start><jupyter_text><jupyter_code>from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt


X,y = make_blobs(n_samples = 150,
                 n_features = 2,
                 centers = 3,
                 cluster_std = 0.5,
                 shuffle = True,
                 random_state = 0)

plt.scatter(X[:,0],
            X[:,1],
            c = 'white',
            marker = 'o',
            edgecolor = 'black',
            s = 50)
plt.grid()
plt.tight_layout()
plt.show()


from sklearn.cluster import KMeans

km = KMeans(n_clusters =3,  # 클러스터 수
            init='random',  # 초기 중심 좌표 무작위
            n_init=10,      # 최소 몇번 실행하여 가장 작은 제곱 오차값을 만드는지 물어본후 가장 낮은거 선택
            max_iter=300,   # 최대 몇번이나 반복적으로 수행하는지
            tol=1e-04,      # 허용 오차값에 도달하면 일찍 종료
            random_state=0)

y_km = km.fit_predict(X)
# 시작화
plt.scatter(X[y_km == 0,0],
            X[y_km == 0,1],
            s = 50, c= 'lightgreen',
            marker = 's', edgecolor = 'black',
            label='cluster 1')
plt.scatter(X[y_km == 1,0],
            X[y_km == 1,1],
            s = 50, c= 'orange',
            marker = 'o', edgecolor = 'black',
            label='cluster 2')
plt.scatter(X[y_km == 2,0],
            X[y_km == 2,1],
            s = 50, c= 'lightblue',
            marker = 'v', edgecolor = 'black',
            label='cluster 3')
plt.scatter(km.cluster_centers_[:,0],
            km.cluster_centers_[:,1],
            s = 250, marker = '*',
            c= 'red', edgecolor = 'black',
            label='centroids')
plt.legend(scatterpoints = 1)
plt.grid()
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14129775621588841, 'fraction_numerical': 0.02971497877501516, 'mean_word_length': 1.7049180327868851, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '97420', 'license': 'MIT', 'n_tokens_mistral': 703, 'n_tokens_neox': 719, 'n_words': 133, 'path': 'ipynb/K_MEANS.ipynb', 'repo_name': 'limjun92/limjun92.github.io', 'size': '1649'}