[docs]classDimRedMethod(ABC):""" Dimensionality reduction methods are algorithms which can be used to reduce the dimensionality of encoded datasets, in order to uncover and analyze patterns present in the data. These methods can be used in the :ref:`ExploratoryAnalysis` and :ref:`Clustering` instructions. """DOCS_TITLE="Dimensionality reduction methods"def__init__(self,name:str=None):self.method=Noneself.name=nameself.components=Nonedef_validate_components(self,n_components=None):ifself.componentsisNone:returnassertisinstance(self.components,list)andlen(self.components)==2 \
andall(isinstance(c,int)andc>=1forcinself.components), \
(f"{self.__class__.__name__}: 'components' must be a list of exactly 2 positive integers "f"(1-indexed), e.g. [3, 4]. Got: {self.components}.")ifn_componentsisnotNoneandisinstance(n_components,int):assertmax(self.components)<=n_components, \
(f"{self.__class__.__name__}: 'components' {self.components} requires n_components >= "f"{max(self.components)}, but n_components is set to {n_components}.")
[docs]definverse_transform(self,transformed_data):try:returnself.method.inverse_transform(transformed_data)exceptException:logging.warning(f"{self.__class__.__name__}: inverse transformation is not supported by this method.")returnNone