From ca2a69f0a2e39cb9329cc64dd2d2abe81031cdbe Mon Sep 17 00:00:00 2001 From: teleplayer123 <40610719+teleplayer123@users.noreply.github.com> Date: Sun, 26 Jan 2020 02:43:00 -0800 Subject: [PATCH] Update working_with_data.py plotting axis along which data best varies --- scratch/working_with_data.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scratch/working_with_data.py b/scratch/working_with_data.py index c50482a7..d2327e45 100644 --- a/scratch/working_with_data.py +++ b/scratch/working_with_data.py @@ -445,6 +445,17 @@ def project(v: Vector, w: Vector) -> Vector: projection_length = dot(v, w) return scalar_multiply(projection_length, w) +data = de_mean(pca_data) +w = first_principal_component(data) +x = [project(v, w) for v in data[:10]] +plt.scatter([v_i[0] for v_i in data], [v_i[1] for v_i in data]) +plt.plot([v_i[0] for v_i in x], [v_i[1] for v_i in x], "r") +plt.xlim(-40, 30) +plt.ylim(-30, 30) +#plt.show() +plt.savefig("im/first_principal_component.png") +plt.gca().clear() + from scratch.linear_algebra import subtract def remove_projection_from_vector(v: Vector, w: Vector) -> Vector: