0
0

Kaggle Masterに学ぶ機械学習実践アプローチ 写経 01

Posted at
# %%
print("hello")

# %%
import matplotlib.pyplot as plt 
import numpy as np
import pandas as pd
import seaborn as sns
from sklearn import datasets 
from sklearn import manifold 


# %%
data = datasets.fetch_openml(
    'mnist_784',
    version=1,
    return_X_y=True
)

pixel_values, targets = data 
targets = targets.astype(int)

# %%
pixel_values

# %%
single_image = pixel_values[0:1].to_numpy().reshape(28, 28)

# %%
plt.imshow(single_image, cmap='gray')

# %%
tsne = manifold.TSNE(n_components=2, random_state=42)
transformed_data = tsne.fit_transform(pixel_values.to_numpy()[:3000, : ])

# %%
tsne_df = pd.DataFrame(
    np.column_stack((transformed_data, targets[:3000])),
    columns=["x", "y", "targets"]
)
tsne_df.loc[:, "targets"] = tsne_df.targets.astype(int)

# %%
tsne_df

# %%
grid=sns.FacetGrid(tsne_df, hue="targets")
grid.map(plt.scatter, "x", "y").add_legend()

# %%



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0