[docs]classTSNE(DimRedMethod):""" t-distributed Stochastic Neighbor Embedding (t-SNE) method which wraps scikit-learn's TSNE. It can be useful for visualizing high-dimensional data. Input arguments for the method are the same as supported by scikit-learn (see `TSNE scikit-learn documentation <https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html#sklearn.manifold.TSNE>`_ for details), plus one additional immuneML argument: - components (list): which two components (1-indexed) to use for visualization in the :ref:`DimensionalityReduction` report. Default: [1, 2]. **YAML specification:** .. indent with spaces .. code-block:: yaml definitions: ml_methods: my_tsne: TSNE: n_components: 2 init: pca components: [1, 2] """def__init__(self,name:str=None,**kwargs):super().__init__(name)self.components=kwargs.pop('components',None)self.method_kwargs=kwargsself.method=SklearnTSNE(**self.method_kwargs)self._validate_components(self.method.n_components)
[docs]deftransform(self,dataset:Dataset=None,design_matrix:np.ndarray=None):logging.warning(f"{TSNE.__name__}: calling transform method of TSNE, but it only supports fit_transform. "f"Fitting the model and returning the transformed data...")data=dataset.encoded_data.get_examples_as_np_matrix()ifdatasetisnotNoneelsedesign_matrixreturnself.method.fit_transform(data)