Skip to content
Snippets Groups Projects
UMAP_.py 1.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • DIANE's avatar
    DIANE committed
    # UMAP function for the Sample Selection module
    from Packages import * 
    from Class_Mod.DATA_HANDLING import * 
    
    
    DIANE's avatar
    DIANE committed
    
    class Umap:
    
        """
        The UMAP dimension reduction algorithm from scikit learn
        """
        def __init__(self, data_import, numerical_data, cat_data):
            self.x = data_import
            self.numerical_data = numerical_data
            if len(cat_data) > 0:
                self.categorical_data = cat_data
                self.le = LabelEncoder()
                self.categorical_data_encoded = self.le.fit_transform(self.categorical_data)
    
    DIANE's avatar
    DIANE committed
    
    
            else:
                self.categorical_data = False
    
            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)
            self.scores_raw = self.model.transform(self.numerical_data)
            self.scores = pd.DataFrame(self.scores_raw, index = self.x.index)
    
    DIANE's avatar
    DIANE committed
    
        @property
        def scores_(self):
    
            return self.scores
        @property
        def scores_raw_(self):
            return self.scores_raw