giotto-ai / giotto-tda

A high-performance topological machine learning toolbox in Python
https://giotto-ai.github.io/gtda-docs
Other
858 stars 175 forks source link

Use PCA as filter function #622

Closed OmarRafique closed 2 years ago

OmarRafique commented 2 years ago

Could you please help me with the code that uses PCA as a filter function for the Mapper.

ulupo commented 2 years ago

Hi! You can pass an instance of scikit-learn's PCA class (https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html) as the filter function. If you have not already consulted our official documentation website, please do so as there are several resources there to get you started.

OmarRafique commented 2 years ago
from sklearn.decomposition import PCA
filter_func = PCA(n_components=2)

That worked. Thanks!!!

OmarRafique commented 2 years ago

Will TSNE work the same way???

ulupo commented 2 years ago

Yes. You can pass arbitrary objects with a fit_transform method, so arbitrary scikit-learn transfomers. You can even pass arbitrary functions which act on 1D vectors. See https://giotto-ai.github.io/gtda-docs/0.5.1/modules/generated/mapper/pipeline/gtda.mapper.make_mapper_pipeline.html.

OmarRafique commented 2 years ago

Could you please give a code example to use tSNE as a filter function?

ulupo commented 2 years ago

This is as simple as importing the tSNE class from scikit-learn

from sklearn.manifold import TSNE

and using an instance of this class as a filter function in make_mapper_pipeline. Please read the tutorial https://giotto-ai.github.io/gtda-docs/0.5.1/notebooks/mapper_quickstart.html for more details.