Spaces:
Sleeping
Sleeping
Commit
·
0b1127d
1
Parent(s):
1588088
modulo means
Browse files- __pycache__/means.cpython-311.pyc +0 -0
- app.py +6 -11
- means.py +10 -0
__pycache__/means.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/means.cpython-311.pyc and b/__pycache__/means.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -1,41 +1,36 @@
|
|
| 1 |
import folium
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import streamlit as st
|
| 4 |
-
from sklearn.cluster import KMeans
|
| 5 |
from streamlit_folium import folium_static
|
| 6 |
|
| 7 |
import geocoding
|
|
|
|
| 8 |
|
| 9 |
st.set_page_config(layout='wide') # Para usar todo el ancho de la página
|
| 10 |
|
| 11 |
-
max_k = len(geocoding.coordenadas)
|
| 12 |
-
inertias = []
|
| 13 |
-
for k in range(2, max_k + 1):
|
| 14 |
-
modelo = KMeans(n_clusters=k, random_state=42)
|
| 15 |
-
modelo.fit(geocoding.coordenadas)
|
| 16 |
-
inertias.append(modelo.inertia_)
|
| 17 |
-
|
| 18 |
# Titulo
|
| 19 |
|
| 20 |
# Ajustar el tamaño del gráfico del codo
|
| 21 |
col1, col2, col3 = st.columns(3)
|
| 22 |
|
|
|
|
| 23 |
with col2:
|
| 24 |
col2.title('Clientes por Zonas')
|
| 25 |
|
| 26 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 27 |
-
ax.plot(range(2, max_k + 1), inertias, marker='o')
|
| 28 |
ax.set_xlabel('Número de zonas (k)')
|
| 29 |
ax.set_ylabel('Inercia')
|
| 30 |
ax.set_title('Método del Codo')
|
| 31 |
st.pyplot(fig)
|
| 32 |
|
|
|
|
| 33 |
k_optimo = st.number_input(
|
| 34 |
"Ingrese el valor óptimo de k según el gráfico:", min_value=2,
|
| 35 |
-
max_value=max_k, step=1
|
| 36 |
)
|
| 37 |
|
| 38 |
-
modelo = KMeans(n_clusters=k_optimo, random_state=42)
|
| 39 |
modelo.fit(geocoding.coordenadas)
|
| 40 |
|
| 41 |
etiquetas = modelo.labels_
|
|
|
|
| 1 |
import folium
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import streamlit as st
|
|
|
|
| 4 |
from streamlit_folium import folium_static
|
| 5 |
|
| 6 |
import geocoding
|
| 7 |
+
import means
|
| 8 |
|
| 9 |
st.set_page_config(layout='wide') # Para usar todo el ancho de la página
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Titulo
|
| 12 |
|
| 13 |
# Ajustar el tamaño del gráfico del codo
|
| 14 |
col1, col2, col3 = st.columns(3)
|
| 15 |
|
| 16 |
+
# Gráfico del Codo
|
| 17 |
with col2:
|
| 18 |
col2.title('Clientes por Zonas')
|
| 19 |
|
| 20 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 21 |
+
ax.plot(range(2, means.max_k + 1), means.inertias, marker='o')
|
| 22 |
ax.set_xlabel('Número de zonas (k)')
|
| 23 |
ax.set_ylabel('Inercia')
|
| 24 |
ax.set_title('Método del Codo')
|
| 25 |
st.pyplot(fig)
|
| 26 |
|
| 27 |
+
# Input de K
|
| 28 |
k_optimo = st.number_input(
|
| 29 |
"Ingrese el valor óptimo de k según el gráfico:", min_value=2,
|
| 30 |
+
max_value=means.max_k, step=1
|
| 31 |
)
|
| 32 |
|
| 33 |
+
modelo = means.KMeans(n_clusters=k_optimo, random_state=42)
|
| 34 |
modelo.fit(geocoding.coordenadas)
|
| 35 |
|
| 36 |
etiquetas = modelo.labels_
|
means.py
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sklearn.cluster import KMeans
|
| 2 |
+
|
| 3 |
+
import geocoding
|
| 4 |
+
|
| 5 |
+
max_k = len(geocoding.coordenadas)
|
| 6 |
+
inertias = []
|
| 7 |
+
for k in range(2, max_k + 1):
|
| 8 |
+
modelo = KMeans(n_clusters=k, random_state=42)
|
| 9 |
+
modelo.fit(geocoding.coordenadas)
|
| 10 |
+
inertias.append(modelo.inertia_)
|