<jupyter_start><jupyter_text>1. load data<jupyter_code># load data
from sklearn.datasets import load_digits

digits = load_digits()

x_data = digits.data
y_data = digits.target
x_data.shape
y_data.shape<jupyter_output><empty_output><jupyter_text>2. PCA<jupyter_code># pca
from sklearn.decomposition import PCA
pca = PCA(n_components=3) # 3 for 3d plot
x_data_new = pca.fit_transform(x_data)
x_data_new.shape<jupyter_output><empty_output><jupyter_text>3. plot 3d<jupyter_code># plot 3d
import joblib as jl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

new_X = x_data_new
y = y_data

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(new_X[:, 0], new_X[:, 1], new_X[:, 2], c=y, cmap=plt.cm.spectral)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12129032258064516, 'fraction_numerical': 0.01806451612903226, 'mean_word_length': 6.918367346938775, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '367412', 'license': 'MIT', 'n_tokens_mistral': 348, 'n_tokens_neox': 337, 'n_words': 65, 'path': 'matplotlib/3d_plot_with_pca.ipynb', 'repo_name': 'ybdesire/machinelearning', 'size': '775'}