Spaces:
Running
Running
Added clustering
Browse files- sections/analytics.py +9 -7
sections/analytics.py
CHANGED
|
@@ -66,16 +66,17 @@ if st.button("Start clustering"):
|
|
| 66 |
# Appliquer K-Means avec k optimal choisi
|
| 67 |
k_optimal = 2 # Par exemple, supposons que k = 3
|
| 68 |
kmeans = KMeans(n_clusters=k_optimal, random_state=42)
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
# Appliquer DBSCAN (epsilon et min_samples sont des hyperparamètres)
|
| 73 |
# dbscan = DBSCAN(eps=0.5, min_samples=10)
|
| 74 |
-
#
|
|
|
|
| 75 |
|
| 76 |
-
# Appliquer Agglomerative Clustering
|
| 77 |
# agg_clustering = AgglomerativeClustering(n_clusters=2)
|
| 78 |
-
#
|
|
|
|
| 79 |
|
| 80 |
###############################################################
|
| 81 |
#### Visualisation des clusters ####
|
|
@@ -102,7 +103,8 @@ if st.button("Start clustering"):
|
|
| 102 |
yaxis_title='Component 2'
|
| 103 |
)
|
| 104 |
|
| 105 |
-
fig.show()
|
|
|
|
| 106 |
|
| 107 |
except Exception as e:
|
| 108 |
st.error(f"An error occured : {e}")
|
|
|
|
| 66 |
# Appliquer K-Means avec k optimal choisi
|
| 67 |
k_optimal = 2 # Par exemple, supposons que k = 3
|
| 68 |
kmeans = KMeans(n_clusters=k_optimal, random_state=42)
|
| 69 |
+
preds = kmeans.fit_predict(df.to_pandas())
|
| 70 |
+
df = df.with_columns(pl.Series(values=preds, name='cluster_kmeans'))
|
| 71 |
+
|
| 72 |
|
|
|
|
| 73 |
# dbscan = DBSCAN(eps=0.5, min_samples=10)
|
| 74 |
+
# preds = dbscan.fit_predict(df.to_pandas())
|
| 75 |
+
# df = df.with_columns(pl.Series(values=preds, name='cluster_dbscan'))
|
| 76 |
|
|
|
|
| 77 |
# agg_clustering = AgglomerativeClustering(n_clusters=2)
|
| 78 |
+
# preds = agg_clustering.fit_predict(df.to_pandas())
|
| 79 |
+
# df = df.with_columns(pl.Series(values=preds, name='cluster_agg'))
|
| 80 |
|
| 81 |
###############################################################
|
| 82 |
#### Visualisation des clusters ####
|
|
|
|
| 103 |
yaxis_title='Component 2'
|
| 104 |
)
|
| 105 |
|
| 106 |
+
# fig.show()
|
| 107 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 108 |
|
| 109 |
except Exception as e:
|
| 110 |
st.error(f"An error occured : {e}")
|