<jupyter_start><jupyter_text>Leitura dos dados<jupyter_code>df = pd.read_csv('Mall_Customers.csv')
df.head()
df.shape<jupyter_output><empty_output><jupyter_text>Verificar dados nulos<jupyter_code>df.isnull().sum()<jupyter_output><empty_output><jupyter_text>Informações estatísticas<jupyter_code>df.describe()<jupyter_output><empty_output><jupyter_text>Gerando gráfico de renda anual versus score do cliente<jupyter_code>plt.scatter(df['Annual Income (k$)'], df['Spending Score (1-100)'], marker='.')
plt.xlabel('Renda Anual [k$]')
plt.ylabel('Score (1-100)')
plt.show()<jupyter_output><empty_output><jupyter_text>Selecioando dados para agrupamento<jupyter_code>X = df[['Annual Income (k$)', 'Spending Score (1-100)']]
X.head()<jupyter_output><empty_output><jupyter_text>Importando K-means<jupyter_code>from sklearn.cluster import KMeans<jupyter_output><empty_output><jupyter_text>Clusterizando com k = 5<jupyter_code>modelo_kmeans = KMeans(n_clusters= 5, init='k-means++')
y_kmeans= modelo_kmeans.fit_predict(X)
print(y_kmeans)<jupyter_output>[2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2
 3 2 3 2 3 2 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 0 4 0 1 0 4 0 4 0 1 0 4 0 4 0 4 0 4 0 1 0 4 0 4 0
 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4
 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0]<jupyter_text>Visualizando o primeiro grupo criado<jupyter_code>print(X[y_kmeans == 0])<jupyter_output>Annual Income (k$)  Spending Score (1-100)
123                  69                      91
125                  70                      77
127                  71                      95
129                  71                      75
131                  71                      75
133                  72                      71
135                  73                      88
137                  73                      73
139                  74                      72
141                  75                      93
143                  76                      87
145                  77                      97
147                  77                      74
149                  78                      90
151                  78                      88
153                  78                      76
155                  78                      89
157                  78                      78
159                  78                      73
161                  79                 [...]<jupyter_text>Visualizando os grupos<jupyter_code>k_grupos = 5
cores = ['r', 'b', 'k', 'y', 'g']
for k in range(k_grupos):
    cluster = X[y_kmeans == k]
    plt.scatter(cluster['Annual Income (k$)'], cluster['Spending Score (1-100)'],
                s = 100, c = cores[k], label = f'Cluster {k}')


plt.title('Grupos de clientes')
plt.xlabel('Renda Anual (k$)')
plt.ylabel('Score (1-100)')
plt.grid()
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09175531914893617, 'fraction_numerical': 0.12267287234042554, 'mean_word_length': 1.5222129086336966, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 51, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '335339', 'license': 'MIT', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1010, 'n_words': 361, 'path': 'Material, Exercicios/Codigos/iadell7_K_means_video_aula.ipynb', 'repo_name': 'maxwell353/Inteligencia-Artificial-DELL', 'size': '3008'}