<jupyter_start><jupyter_text>Dimensionality Reduction<jupyter_code>blob_coords, _ = make_blobs(n_samples = 1000, n_features = 2, centers = 1)
def plot_blobs(blob_coords):
    plt.scatter(blob_coords[:, 0], blob_coords[:, 1], s = 1)
    plt.gca().set_aspect('equal')
    plt.show()
plot_blobs(blob_coords)
transform_matrix = np.array([
    [0.7, 1.5],
    [1, 0.3]
])
X = blob_coords @ transform_matrix
plot_blobs(X)
X.mean(axis = 0)
pca = PCA()
pca.fit(X)
pca.components_
pca.transform(X)
pca.explained_variance_ratio_
pca.explained_variance_
v1 = pca.components_[0] * np.sqrt(pca.explained_variance_[0]) * 2
v2 = pca.components_[1] * np.sqrt(pca.explained_variance_[1]) * 2
v1, v2
plt.scatter(X[:, 0], X[:, 1], s = 1)
plt.quiver([pca.mean_[0]], [pca.mean_[1]], [v1[0]], [v1[1]], scale_units = "xy", angles = "xy", scale = 1, color = "red")
plt.quiver([pca.mean_[0]], [pca.mean_[1]], [v2[0]], [v2[1]], scale_units = "xy", angles = "xy", scale = 1, color = "red")

plt.gca().set_aspect('equal')
plt.show()
pca.mean_
pca.components_[0][0]
plot_blobs(pca.transform(X))
plot_blobs(pca.inverse_transform(pca.transform(X)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2005231037489102, 'fraction_numerical': 0.04010462074978204, 'mean_word_length': 5.874251497005988, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '632869', 'license': 'MIT', 'n_tokens_mistral': 530, 'n_tokens_neox': 506, 'n_words': 84, 'path': 'dimensionality_reduction/Dimensionality Reduction Regression Demos.ipynb', 'repo_name': 'PetkoAndreev/Python-Machine-Learning', 'size': '1147'}