Cyr-CK commited on
Commit
78f91c5
·
1 Parent(s): b3ce1b2

Added clustering

Browse files
Files changed (1) hide show
  1. 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
- df = df.with_columns(pl.Series(kmeans.fit_predict(df.to_pandas()), name='cluster_kmeans'))
70
- st.write(df[:10])
 
71
 
72
- # Appliquer DBSCAN (epsilon et min_samples sont des hyperparamètres)
73
  # dbscan = DBSCAN(eps=0.5, min_samples=10)
74
- # df = df.with_columns(pl.Series(dbscan.fit_predict(df.to_pandas()), name='cluster_dbscan'))
 
75
 
76
- # Appliquer Agglomerative Clustering
77
  # agg_clustering = AgglomerativeClustering(n_clusters=2)
78
- # df = df.with_columns(pl.Series(agg_clustering.fit_predict(df.to_pandas()), name='cluster_agg'))
 
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}")