Skip to content

Instantly share code, notes, and snippets.

@KhyatiMahendru
Created July 23, 2019 05:47
Show Gist options
  • Save KhyatiMahendru/c21b697fcad05fdd55919250f8d07205 to your computer and use it in GitHub Desktop.
Save KhyatiMahendru/c21b697fcad05fdd55919250f8d07205 to your computer and use it in GitHub Desktop.
import numpy as np
from sklearn.decomposition import TruncatedSVD
A = np.array([[-1, 2, 0], [2, 0, -2], [0, -2, 1]])
print("Original Matrix:")
print(A)
svd = TruncatedSVD(n_components = 2)
A_transf = svd.fit_transform(A)
print("Singular values:")
print(svd.singular_values_)
print("Transformed Matrix after reducing to 2 features:")
print(A_transf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment