Skip to content
Snippets Groups Projects
Commit 41be0373 authored by DIANE's avatar DIANE
Browse files

samples selection

parent 34dfdae4
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ class Umap:
self.model = UMAP(n_neighbors=20, n_components=4, min_dist=0.0,) # random_state=42,)
self.model.fit(self.x)
self.scores = self.model.transform(self.x)
self.scores = pd.DataFrame(self.scores, index = self.numerical_data.index)
self.scores = pd.DataFrame(self.scores)
@property
def scores_(self):
......
......@@ -101,17 +101,18 @@ if not spectra.empty:
# clustering
if not t.empty:
tcr = standardize(t)
# Clustering
if clus_method == cluster_methods[1]:
ncluster = scores.number_input(min_value=2, max_value=30, value=3, label = 'Select the desired number of clusters')
cl_model = Sk_Kmeans(t, max_clusters = 30)
fig2 = px.scatter(cl_model.inertia_.T, y = 'inertia')
scores.plotly_chart(fig2)
data, labels = cl_model.fit_optimal(nclusters = ncluster)
elif clus_method == cluster_methods[2]:
from hdbscan import HDBSCAN_function
labels, hdbscan_score = HDBSCAN_function(t, min_cluster_size=10)
if clus_method == cluster_methods[1]:
ncluster = scores.number_input(min_value=2, max_value=30, value=3, label = 'Select the desired number of clusters')
cl_model = Sk_Kmeans(tcr, max_clusters = 30)
fig2 = px.scatter(cl_model.inertia_.T, y = 'inertia')
scores.plotly_chart(fig2)
data, labels = cl_model.fit_optimal(nclusters = ncluster)
elif clus_method == cluster_methods[2]:
from hdbscan import HDBSCAN_function
labels, hdbscan_score = HDBSCAN_function(tcr, min_cluster_size=10)
##### Plots
......@@ -122,16 +123,16 @@ if not t.empty:
st.write('Scores plot')
# scores plot with clustering
if list(labels) and meta_data.empty:
fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = labels)
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = labels)
# scores plot with metadata
elif len(list(labels)) == 0 and not meta_data.empty:
filter = meta_data.columns[1:]
col = st.selectbox('Group by:', options= filter)
if col == 0:
fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3)
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3)
else:
fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col])) )
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col])) )
# color with scores and metadata
elif len(list(labels)) > 0 and not meta_data.empty:
......@@ -143,14 +144,14 @@ if not t.empty:
col = st.selectbox('Group by:', options= filter)
if col == "None":
fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3)
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3)
elif col == clus_method:
fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = labels)
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = labels)
else:
fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col])))
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col])))
else:
fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3)
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3)
fig.update_traces(marker=dict(size=4))
st.plotly_chart(fig)
......@@ -183,7 +184,4 @@ if not spectra.empty:
hotelling = dr_model.hotelling_
fig = px.scatter(t, x=hotelling[ax2], y=residuals[ax2]).update_layout(xaxis_title="",yaxis_title="Residuals")
st.plotly_chart(fig)
st.plotly_chart(fig)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment