[PYTHON] [Note] PCA and t-SNE

import

import scipy as sp
import sklearn.base
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
import pandas as pd

Read data

data = 'table_rdf.csv'
df = pd.read_csv(data,index_col=0).dropna(axis=1)

Execution of t-SNE

X_reduced = TSNE(n_components=2, random_state=0).fit_transform(df)

Color coding settings Read data

data_2 = 'y_rdf.csv'
df_2 = pd.read_csv(data_2,index_col=0).dropna(axis=1)

Sort in column direction (vertical direction)

df2_s = df_2.sort_index()
df2_s.head()

merge

df_merge = pd.merge(df, df_2, how='left',right_index=True,left_index=True)
df_merge.head()

Print

plt.scatter(X_reduced[:, 0], X_reduced[:, 1], c=df_merge['target'])
plt.colorbar()

Do PCA

from sklearn.decomposition import PCA
pca = PCA(n_components=2).fit(df)
values = pca.transform(df)
fig = plt.figure()
plt.scatter(values[:,0], values[:,1], c=df_merge['target'])
plt.xlabel("value1")
plt.ylabel("value2")
plt.colorbar()
plt.show()

Recommended Posts

[Note] PCA and t-SNE
Understand t-SNE and improve visualization
Note
[Note] Django project creation and terminology
[Note] Conflict between matplotlib and zstd
(Note) Difference between gateway and default gateway
t-SNE
[Note] WSL2 kernel build and use
Note
Note: Linux concepts and minimum commands