diff --git a/frontend/pages/clustering.py b/frontend/pages/clustering.py new file mode 100644 index 0000000..037780d --- /dev/null +++ b/frontend/pages/clustering.py @@ -0,0 +1,48 @@ +import streamlit as st +from sklearn.cluster import KMeans +import matplotlib.pyplot as plt + +st.header("clustering et Prediction") + + +if "data" in st.session_state: + data = st.session_state.data + + with st.form("my_form"): + header = st.columns([2,1,2]) + header[0].subheader("Dispersion") + header[1].subheader("Number of clusters") + header[2].subheader("Data Name") + + row1 = st.columns([2,1,2]) + cluster_std = row1[0].slider("", 0.2, 3.0, 0.2, 0.2) + n_clusters = row1[1].selectbox("", range(1, 10)) + data_name = row1[2].selectbox("", data.columns) + + st.form_submit_button('launch') + + from sklearn.datasets import make_blobs + from sklearn.cluster import KMeans + import matplotlib.pyplot as plt + import streamlit as st + import random + + # Points generator + x, _ = make_blobs(n_samples=200, n_features=2, centers=5, cluster_std=cluster_std, shuffle=True, random_state=10) + + x = data[["Unit Price","Unit Cost"]].to_numpy() + + # k-means algorithm + kmeans = KMeans(n_clusters=n_clusters, init='random', n_init=10, max_iter=300, random_state=111) + y_kmeans = kmeans.fit_predict(x) + + # Plotting colored clusters + fig, ax = plt.subplots(figsize=(12,8)) + plt.scatter(x[:, 0], x[:, 1], s=100, c=kmeans.labels_, cmap='Set1') + plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s=400, marker='*', color='k') + st.pyplot(fig) + +else: + st.error("file not loaded") + +# Cached function that returns a mutable object with a random number in the range 0-10 \ No newline at end of file