Implementation:Scikit learn Scikit learn BenchPlotRandomizedSVD
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Benchmarking |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for benchmarking randomized SVD power iteration strategies provided by scikit-learn.
Description
This benchmark script evaluates the effect of increasing the number of power iterations in randomized SVD on both approximation quality and running time. It tests several normalization policies (none, LU, QR, auto) and compares them against fbpca if installed. The quality of approximation is measured by the spectral norm discrepancy between the original and reconstructed matrices. The benchmarks test on various synthetic and real datasets.
Usage
Use this benchmark to determine the optimal number of power iterations and normalization policy for randomized SVD, especially for noisy matrices characterized by slow spectral decay.
Code Reference
Source Location
- Repository: scikit-learn
- File: benchmarks/bench_plot_randomized_svd.py
Signature
# Key function benchmarked
from sklearn.utils.extmath import randomized_svd
# Comparison algorithms:
# randomized_svd(..., power_iteration_normalizer='none')
# randomized_svd(..., power_iteration_normalizer='LU')
# randomized_svd(..., power_iteration_normalizer='QR')
# randomized_svd(..., power_iteration_normalizer='auto')
# fbpca.pca() (if installed)
Import
from sklearn.utils.extmath import randomized_svd
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| M | ndarray | Yes | Input matrix for SVD decomposition |
| n_components | int | Yes | Number of singular values/vectors to extract |
| n_iter | int | No | Number of power iterations (default varies) |
| power_iteration_normalizer | str | No | Normalization policy: 'none', 'LU', 'QR', or 'auto' |
Outputs
| Name | Type | Description |
|---|---|---|
| Plots | matplotlib figures | Time vs norm plots, n_iter vs norm plots, comparison plots |
| Console output | text | Timing and accuracy metrics for each configuration |
Usage Examples
Basic Usage
import numpy as np
from sklearn.utils.extmath import randomized_svd
# Generate a low-rank matrix
rng = np.random.RandomState(42)
A = rng.randn(1000, 100)
U, S, Vt = randomized_svd(A, n_components=10, n_iter=5,
power_iteration_normalizer='QR',
random_state=42)
print("Singular values:", S[:5])