Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.decomposition import PCA
- import numpy as np
- X = np.arange(20).reshape((5,4))
- print("Separate")
- XT = X.copy()
- pcaT = PCA(n_components=2, copy=True)
- print("Original: ", XT)
- results = pcaT.fit(XT).transform(XT)
- print("New: ", XT)
- print("Results: ", results)
- print("nCombined")
- XF = X.copy()
- pcaF = PCA(n_components=2, copy=True)
- print("Original: ", XF)
- results = pcaF.fit_transform(XF)
- print("New: ", XF)
- print("Results: ", results)
- ########## Results
- Separate
- Original: [[ 0 1 2 3]
- [ 4 5 6 7]
- [ 8 9 10 11]
- [12 13 14 15]
- [16 17 18 19]]
- New: [[ 0 1 2 3]
- [ 4 5 6 7]
- [ 8 9 10 11]
- [12 13 14 15]
- [16 17 18 19]]
- Results: [[ 1.60000000e+01 -2.66453526e-15]
- [ 8.00000000e+00 -1.33226763e-15]
- [ 0.00000000e+00 0.00000000e+00]
- [ -8.00000000e+00 1.33226763e-15]
- [ -1.60000000e+01 2.66453526e-15]]
- Combined
- Original: [[ 0 1 2 3]
- [ 4 5 6 7]
- [ 8 9 10 11]
- [12 13 14 15]
- [16 17 18 19]]
- New: [[ 0 1 2 3]
- [ 4 5 6 7]
- [ 8 9 10 11]
- [12 13 14 15]
- [16 17 18 19]]
- Results: [[ 1.60000000e+01 1.44100598e-15]
- [ 8.00000000e+00 -4.80335326e-16]
- [ -0.00000000e+00 0.00000000e+00]
- [ -8.00000000e+00 4.80335326e-16]
- [ -1.60000000e+01 9.60670651e-16]]
Add Comment
Please, Sign In to add comment