Skip to content
Snippets Groups Projects
Commit c1ef0d45 authored by BARTHES Nicolas's avatar BARTHES Nicolas
Browse files

supervised UMAP working with metadata

parent 8ad6a010
No related branches found
No related tags found
No related merge requests found
# UMAP function for the Sample Selection module
from Packages import *
from Class_Mod.DATA_HANDLING import *
from Packages import *
from Class_Mod.DATA_HANDLING import *
class Umap:
......@@ -10,13 +10,14 @@ class Umap:
def __init__(self, data_import, numerical_data, cat_data):
self.x = data_import
self.numerical_data = numerical_data
if len(cat_data) > 0:
if cat_data is None:
self.categorical_data_encoded = cat_data
elif len(cat_data) > 0:
self.categorical_data = cat_data
self.le = LabelEncoder()
self.categorical_data_encoded = self.le.fit_transform(self.categorical_data)
else:
self.categorical_data = False
self.categorical_data_encoded = None
self.model = UMAP(n_neighbors=20, n_components=3, min_dist=0.0, random_state=42,)
self.model.fit(self.numerical_data, y = self.categorical_data_encoded)
......
......@@ -88,7 +88,13 @@ if not spectra.empty:
if dim_red_method == dim_red_methods[1]:
dr_model = LinearPCA(xc, Ncomp=5)
elif dim_red_method == dim_red_methods[2]:
dr_model = Umap(data_import = imp, numerical_data = MinMaxScale(spectra), cat_data = meta_data)
if not meta_data.empty:
filter = meta_data.columns[1:]
col = pc.selectbox('Supervised UMAP by:', options= filter, key=108)
supervised = meta_data[col]
else:
supervised = None
dr_model = Umap(data_import = imp, numerical_data = MinMaxScale(spectra), cat_data = supervised)
if dr_model:
axis1 = pc.selectbox("x-axis", options = dr_model.scores_.columns, index=0)
......@@ -109,7 +115,7 @@ if not t.empty:
data, labels = cl_model.fit_optimal(nclusters = ncluster)
elif clus_method == cluster_methods[2]:
optimized_hdbscan = Hdbscan(model.scores_raw_)
optimized_hdbscan = Hdbscan(dr_model.scores_raw_)
labels, hdbscan_score = optimized_hdbscan.HDBSCAN_scores_
##### Plots
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment