How do I use tsne to visualize data with high dimensionality?

I am trying to use TSNE to visualize data based on a Category to show me if the data is separable.

I have been trying to do this for the past two days but I am not getting a scatter plot showing the different categories plotted to enable me to see the relationship.

Instead, it is plotting all the data in a straight linear line, which cannot be correct as there are 5 different distinct attributes with the column I am trying to use as a label and legend.

What do I do to correct this.

import label as label
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.cm import get_cmap
from matplotlib.colors import rgb2hex

from sklearn.manifold import TSNE
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from matplotlib import pyplot as plt
import numpy as np

#region Making Printing more visible to show all columns and rows

# pandas.set_option('display.max_columns', None)

#endregion

# #region Loading Data
filename = 'Dataset/test.csv'
df = pd.read_csv(filename)
# groups = df.Activity
# print(groups)

label = df.pop('Activity')
label_counts = label.value_counts()
#
#
# # Scale Data
scale = StandardScaler()
tsne_data= scale.fit_transform(df)

print(label)
print(label.unique())

fig, axa = plt.subplots(2, 1, figsize=(15,10))
group = label.unique()


# X_label =
#
for i , labels in label.iteritems():
    # mask =(label = group)
    axa[0].scatter(x = tsne_data, y = tsne_data, label = group)
    plt.legend


    plt.show()


Read more here: https://stackoverflow.com/questions/66265595/how-do-i-use-tsne-to-visualize-data-with-high-dimensionality

Content Attribution

This content was originally published by Creator_py at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: