QinbinLi / MOON

Model-Contrastive Federated Learning (CVPR 2021)
MIT License
263 stars 56 forks source link

Questions about T-SNE #7

Closed knight-fzq closed 2 years ago

knight-fzq commented 2 years ago

Hello,

Thanks for sharing the interesting work, I just have one question about the T-SNE part. Could i know more detailed information about how you generate such amazing T-SNE results and i want to reproduce them. And actually i have tried TSNE of sklearn and open-tsne but they did not work.

QinbinLi commented 2 years ago

Hi @knight-fzq ,

I used sklearn TSNE to generate the results. Here is the sample code for your reference, where features is the feature representations array and targets is the labels array of the input data.

        from sklearn.manifold import TSNE
        import matplotlib.pyplot as plt
        import pandas as pd
        import seaborn as sns

        df = pd.DataFrame()
        tsne = TSNE(n_components=2, verbose=1, perplexity=40, n_iter=300)
        tsne_results = tsne.fit_transform(features)
        df['y'] = targets
        df['tsne-2d-one'] = tsne_results[:,0]
        df['tsne-2d-two'] = tsne_results[:,1]
        fig = plt.figure()
        ax = fig.add_subplot(111)
        sns.scatterplot(
            x="tsne-2d-one", y="tsne-2d-two",
            hue="y",
            palette=sns.color_palette("tab10", 10),
            data=df,
            legend="full",
            alpha=0.8,
            s=5,
            ax=ax
        )
        ax.legend(title='class ID', loc='upper left')
        plt.axis('off')
        plt.show()
knight-fzq commented 2 years ago

Thank you very much.

fanfan-97 commented 2 years ago

I would like to ask you if you have succeeded in reproduction? I also recently read this article to try to reproduce it, but it has been unsuccessful.