Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#pca svd working def svd(D): import time import numpy # Record starting time timestart = time.time() # Prepare and center the data for PCA # Reshape from 3D array to 2D array # from (pics, height, width) # to (pics, all_pixels) # here: from (2000, 62, 47) to (2000, 2914) # then transpose X = D.reshape(len(D), -1).T X -= X.mean(axis=1, keepdims=True) # Singular Value Decomposition U, L, V = numpy.linalg.svd(X / X.shape[1]**0.5, full_matrices=False) # Print time tfinish = time.time() print('Time in seconds: %.3f' % (tfinish - timestart)) # Visualize first two principal components utils.scatterplot(U[:,0].dot(X), U[:,1].dot(X), xlabel='PCA 1', ylabel='PCA 2') # Render first 60 eigenfaces (principal components) utils.render(U[:,:60].T, 15, 4) # call the function svd(D)
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)