Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Inconsistency #2

Open
BradKML opened this issue Oct 4, 2022 · 3 comments
Open

Documentation Inconsistency #2

BradKML opened this issue Oct 4, 2022 · 3 comments

Comments

@BradKML
Copy link

BradKML commented Oct 4, 2022

Currently flameplot only provides a "fig" as a tuple of fig (plot) and ax
https://github.com/erdogant/flameplot/blob/master/flameplot/flameplot.py#L161

But the tuple contains the real fig (plot) and ax
https://github.com/erdogant/scatterd/blob/master/scatterd/scatterd.py#L156

For purposes of saving graphs, this could be fixed.

For testing (given a proper X):

!pip install umap-learn trimap pacmap
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from umap import UMAP # https://github.com/lmcinnes/umap
from trimap import TRIMAP # https://github.com/eamid/trimap
from pacmap import PaCMAP # https://github.com/YingfanWang/PaCMAP

k = 3
mapper = [TSNE(n_components=k), 
  # UMAP(n_components=k),
  # TRIMAP(n_dims=k),
  PaCMAP(n_components=k)
]

from flameplot import scatter, compare, plot

pca_standard = PCA().fit_transform(X)

for i in mapper:
  title = type(i).__name__ # name of the object class
  transformed = i.fit_transform(X)
  fig, _ = scatter(transformed[:,0], transformed[:,1], labels=y['country'], s=75, title=title)
  fig.savefig(title+'_2D.png')
  scores = compare(pca_standard, transformed, n_steps=5)
  fig, _ = plot(scores, xlabel='PCA', ylabel=title)
  fig.savefig(title+'_factors.png')
@erdogant
Copy link
Owner

erdogant commented Oct 5, 2022

Is your suggestion to only return fig and not ax?

@BradKML
Copy link
Author

BradKML commented Oct 5, 2022

Current edit might makes things clearer, it might be good to always return fig and ax, and have the documentation match the standard output.

!pip install umap-learn trimap pacmap
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from umap import UMAP # https://github.com/lmcinnes/umap
from trimap import TRIMAP # https://github.com/eamid/trimap
from pacmap import PaCMAP # https://github.com/YingfanWang/PaCMAP

k = 3
mapper = [TSNE(n_components=k), UMAP(n_components=k), TRIMAP(n_dims=k), PaCMAP(n_components=k)]

from  flameplot import scatter, compare, plot

pca_standard = PCA().fit_transform(X.to_numpy())

def scatter_maker(transformed, title, labels=y['country']):
  fig1, _ = scatter(transformed[:,0], transformed[:,1], labels=y, s=75, title=title)
  # documentation claimed there is only `(fig)` and not `(fig, ax)`
  # https://github.com/erdogant/scatterd/blob/master/scatterd/scatterd.py#L156
  # https://github.com/erdogant/flameplot/blob/master/flameplot/flameplot.py#L161
  fig1.savefig(title+'_2D.png')
  pass

def compare_maker(transformed, title, pca_standard=pca_standard):
  scores = compare(pca_standard, transformed, n_steps=5)
  fig2 = plot(scores, xlabel='PCA', ylabel=title) # not follow the `(fig, ax)` design pattern
  # https://github.com/erdogant/imagesc/blob/master/imagesc/imagesc.py#L243
  # https://github.com/erdogant/flameplot/blob/master/flameplot/flameplot.py#L138
  fig2.savefig(title+'_factors.png')
  pass

for i in mapper:
  title = type(i).__name__ # name of the object class
  transformed = i.fit_transform(X.to_numpy())
  # to_numpy is needed for TriMAP and PaCMAP
  scatter_maker(transformed, title, y)
  compare_maker(transformed, title, pca_standard=pca_standard)

@erdogant
Copy link
Owner

erdogant commented Oct 7, 2022

Agree. The output is now (fig, ax) and is also changed in the documentation pages.

Update to the latest version with:

pip install -U flameplot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants