# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="I93eS3Lyl-3y"
# d : 폴더, - : 파일
# list명령어 상세 출력결과 라인별 첫 단어 의미
#

# + colab={"base_uri": "https://localhost:8080/"} id="8Zt0MigiffSE" outputId="ff124416-9e43-4b90-aad6-2d7b95ad7163"
# !ls

# + colab={"base_uri": "https://localhost:8080/"} id="ezZpxsrTfjK9" outputId="c49c7124-40f1-46f1-9a5b-d71c5177e5bc"
# !ls -l

# + colab={"base_uri": "https://localhost:8080/"} id="bwpSpJdzfjTH" outputId="144daed1-4bff-4fc7-e35b-dda5303f94bc"
# !pwd

# + colab={"base_uri": "https://localhost:8080/"} id="zW2piJLtgyAt" outputId="c94bffd3-443a-4a20-c13f-2c8ba164212d"
# !ls -l ./sample_data

# + colab={"base_uri": "https://localhost:8080/"} id="Y4SiLyQJgyE4" outputId="3599e10b-4223-487d-a4ed-022e32930bd0"
# !ls -l ./Wholesale_customers_data.csv

# + colab={"base_uri": "https://localhost:8080/"} id="CxW4QzrFipAR" outputId="870de077-dd5a-4207-9b13-f9bca81bf59e"
import pandas as pd
df = pd.read_csv('Wholesale_customers_data.csv')
df.info()

# + id="keccM6eLsFjX"
X = df.iloc[:,:]

# + colab={"base_uri": "https://localhost:8080/"} id="7Dq8pqYesXJm" outputId="bee0785b-3401-4c02-b83e-1ef5289b69dc"
X.shape

# + id="fHPWhRKCsYOc"
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X)
X = scaler.transform(X)

# + id="s1h4qTPjswQq"
from sklearn import cluster
kmeans = cluster.KMeans(n_clusters=5)

# + colab={"base_uri": "https://localhost:8080/"} id="11BB7ORmunza" outputId="06a35cbf-3b28-4b55-f351-9052ac77a50f"
kmeans.fit(X)

# + colab={"base_uri": "https://localhost:8080/"} id="DHwiV-jvuuhu" outputId="9d929482-6f95-49db-9f9d-cacc1ae6c8b8"
kmeans.labels_

# + id="_KyPtKI3vIZ5"
df['label'] = kmeans.labels_

# + colab={"base_uri": "https://localhost:8080/", "height": 203} id="5L5oWL5vveN_" outputId="8fe40378-034e-4c21-8fcd-cd0f0016740c"
df.head()

# + colab={"base_uri": "https://localhost:8080/", "height": 602} id="qZHPFJeyvfGJ" outputId="ab862dde-d31f-4e5e-94e4-8e4ded2bb934"
df.plot(kind='scatter', x='Grocery', y = 'Frozen', c = 'label', cmap = 'Set1', figsize = (10,10))        #c는 중심점

# + colab={"base_uri": "https://localhost:8080/"} id="woewsr32xIFw" outputId="fd142049-cb4d-4d27-ceb3-69e939d44d62"
# for ...:
#   if ~((df['label'] == 0) | (df['label'] == 4)):
dfx  = df[~((df['label'] == 0) | (df['label'] == 4))]
df.shape, dfx.shape

# + colab={"base_uri": "https://localhost:8080/", "height": 438} id="j8XpZ2u42noP" outputId="14181c6d-a3ad-4598-8be6-cf820c0a34f0"
dfx.plot(kind='scatter', x='Milk', y = 'Frozen', c = 'label', cmap = 'Set1', figsize = (7,7))

# + id="5_lRo0bn27g7"
df.to_excel('.wholesale.xls')

StarcoderdataJupyterScriptsDedupFiltered