fin separation front/back
This commit is contained in:
@@ -1,35 +1,22 @@
|
||||
import streamlit as st
|
||||
import matplotlib.pyplot as plt
|
||||
from sklearn.cluster import DBSCAN
|
||||
|
||||
st.header("Clustering: dbscan")
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../backend')))
|
||||
from dbscan_strategy import perform_dbscan_clustering
|
||||
|
||||
st.header("Clustering: DBSCAN")
|
||||
|
||||
if "data" in st.session_state:
|
||||
data = st.session_state.data
|
||||
|
||||
with st.form("my_form"):
|
||||
with st.form("dbscan_form"):
|
||||
data_name = st.multiselect("Data Name", data.select_dtypes(include="number").columns, max_selections=3)
|
||||
eps = st.slider("eps", min_value=0.0, max_value=1.0, value=0.5, step=0.01)
|
||||
min_samples = st.number_input("min_samples", step=1, min_value=1, value=5)
|
||||
st.form_submit_button("launch")
|
||||
submitted = st.form_submit_button("Launch")
|
||||
|
||||
if len(data_name) >= 2 and len(data_name) <=3:
|
||||
x = data[data_name].to_numpy()
|
||||
|
||||
dbscan = DBSCAN(eps=eps, min_samples=min_samples)
|
||||
y_dbscan = dbscan.fit_predict(x)
|
||||
|
||||
fig = plt.figure()
|
||||
if len(data_name) == 2:
|
||||
ax = fig.add_subplot(projection='rectilinear')
|
||||
plt.scatter(x[:, 0], x[:, 1], c=y_dbscan, s=50, cmap="viridis")
|
||||
else:
|
||||
ax = fig.add_subplot(projection='3d')
|
||||
ax.scatter(x[:, 0], x[:, 1],x[:, 2], c=y_dbscan, s=50, cmap="viridis")
|
||||
if submitted and 2 <= len(data_name) <= 3:
|
||||
fig = perform_dbscan_clustering(data, data_name, eps, min_samples)
|
||||
st.pyplot(fig)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
st.error("file not loaded")
|
||||
st.error("File not loaded")
|
||||
|
Reference in New Issue
Block a user