Add cluster stats (#13)
Co-authored-by: bastien ollier <bastien.ollier@etu.uca.fr> Reviewed-on: https://codefirst.iut.uca.fr/git/clement.freville2/miner/pulls/13 Reviewed-by: Hugo PRADIER <hugo.pradier2@etu.uca.fr> Reviewed-by: Clément FRÉVILLE <clement.freville2@etu.uca.fr> Co-authored-by: Bastien OLLIER <bastien.ollier@noreply.codefirst.iut.uca.fr> Co-committed-by: Bastien OLLIER <bastien.ollier@noreply.codefirst.iut.uca.fr>
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import streamlit as st
|
||||
from sklearn.cluster import KMeans
|
||||
import matplotlib.pyplot as plt
|
||||
from clusters import KMeans_cluster
|
||||
|
||||
st.header("Clustering: kmeans")
|
||||
|
||||
|
||||
if "data" in st.session_state:
|
||||
data = st.session_state.data
|
||||
|
||||
@@ -23,21 +22,22 @@ if "data" in st.session_state:
|
||||
if len(data_name) >= 2 and len(data_name) <=3:
|
||||
x = data[data_name].to_numpy()
|
||||
|
||||
kmeans = KMeans(n_clusters=n_clusters, init="random", n_init=n_init, max_iter=max_iter, random_state=111)
|
||||
y_kmeans = kmeans.fit_predict(x)
|
||||
kmeans = KMeans_cluster(n_clusters, n_init, max_iter, x)
|
||||
y_kmeans = kmeans.run()
|
||||
|
||||
st.table(kmeans.get_stats())
|
||||
|
||||
centers = kmeans.centers
|
||||
fig = plt.figure()
|
||||
if len(data_name) == 2:
|
||||
ax = fig.add_subplot(projection='rectilinear')
|
||||
plt.scatter(x[:, 0], x[:, 1], c=y_kmeans, s=50, cmap="viridis")
|
||||
centers = kmeans.cluster_centers_
|
||||
plt.scatter(centers[:, 0], centers[:, 1], c="black", s=200, marker="X")
|
||||
else:
|
||||
ax = fig.add_subplot(projection='3d')
|
||||
|
||||
ax.scatter(x[:, 0], x[:, 1],x[:, 2], c=y_kmeans, s=50, cmap="viridis")
|
||||
centers = kmeans.cluster_centers_
|
||||
ax.scatter(centers[:, 0], centers[:, 1],centers[:, 2], c="black", s=200, marker="X")
|
||||
ax.scatter(centers[:, 0], centers[:, 1], centers[:, 2], c="black", s=200, marker="X")
|
||||
st.pyplot(fig)
|
||||
|
||||
else:
|
||||
|
Reference in New Issue
Block a user