<jupyter_start><jupyter_text>Clonamos el repositorio para obtener los dataSet<jupyter_code>!git clone https://github.com/joanby/machinelearning-az.git<jupyter_output><empty_output><jupyter_text>Damos acceso a nuestro Drive<jupyter_code>from google.colab import drive
drive.mount('/content/drive')<jupyter_output><empty_output><jupyter_text>Test it<jupyter_code>!ls '/content/drive/My Drive'<jupyter_output><empty_output><jupyter_text>Google colab tools<jupyter_code>from google.colab import files # Para manejar los archivos y, por ejemplo, exportar a su navegador
import glob # Para manejar los archivos y, por ejemplo, exportar a su navegador
from google.colab import drive # Montar tu Google drive<jupyter_output><empty_output><jupyter_text>Instalar dependendias<jupyter_code>!pip install sklearn<jupyter_output><empty_output><jupyter_text>K-Means  Cómo importar las librerías<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd<jupyter_output><empty_output><jupyter_text>Importar el data set<jupyter_code>dataset = pd.read_csv('/content/machinelearning-az/datasets/Part 4 - Clustering/Section 24 - K-Means Clustering/Mall_Customers.csv')
X = dataset.iloc[:, [3,4]].values<jupyter_output><empty_output><jupyter_text>Método del codo para averiguar el número óptimo de clusters<jupyter_code>from sklearn.cluster import KMeans
wcss = []
for i in range(1, 11):
    kmeans = KMeans(n_clusters = i, init = "k-means++", max_iter = 300, n_init = 10, random_state = 0)
    kmeans.fit(X)
    wcss.append(kmeans.inertia_)

plt.plot(range(1,11), wcss)
plt.title("Método del codo")
plt.xlabel("Número de Clusters")
plt.ylabel("WCSS(k)")
plt.show()<jupyter_output><empty_output><jupyter_text>Aplicar el método de k-means para segmentar el data set<jupyter_code>kmeans = KMeans(n_clusters = 5, init="k-means++", max_iter = 300, n_init = 10, random_state = 0)
y_kmeans = kmeans.fit_predict(X)<jupyter_output><empty_output><jupyter_text>Visualización de los clusters<jupyter_code>plt.scatter(X[y_kmeans == 0, 0], X[y_kmeans == 0, 1], s = 100, c = "red", label = "Cautos")
plt.scatter(X[y_kmeans == 1, 0], X[y_kmeans == 1, 1], s = 100, c = "blue", label = "Estandard")
plt.scatter(X[y_kmeans == 2, 0], X[y_kmeans == 2, 1], s = 100, c = "green", label = "Objetivo")
plt.scatter(X[y_kmeans == 3, 0], X[y_kmeans == 3, 1], s = 100, c = "cyan", label = "Descuidados")
plt.scatter(X[y_kmeans == 4, 0], X[y_kmeans == 4, 1], s = 100, c = "magenta", label = "Conservadores")
plt.scatter(kmeans.cluster_centers_[:,0], kmeans.cluster_centers_[:,1], s = 300, c = "yellow", label = "Baricentros")
plt.title("Cluster de clientes")
plt.xlabel("Ingresos anuales (en miles de $)")
plt.ylabel("Puntuación de Gastos (1-100)")
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14259992797983434, 'fraction_numerical': 0.024486856319769535, 'mean_word_length': 6.825352112676057, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 1, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '369123', 'license': 'MIT', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1089, 'n_words': 232, 'path': 'datasets/Part 4 - Clustering/Section 24 - K-Means Clustering/kmeans.ipynb', 'repo_name': 'aicangas/machinelearning-az', 'size': '2777'}