on-internet
← Community

How can I find the best fit line using PCA in Python?

Stack Overflow ·

I have this code that does it using SVD. But I want to know how to do the same using PCA. Online, all I can find is that they are related, etc., but I am not sure how they are related and how they are different in code, doing the exact same thing. I just want to see how PCA does this differently than SVD. import numpy as np points = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Centering the points mean_point = np.mean(points, axis=0) centered_points = points - mean_point # Calculating the covariance matrix covariance_matrix = np.cov(centered_points, rowvar=False) # Performing the SVD U, s, V

Comments

Sign in or sign up to comment and upvote.

No comments yet.