๐ Introduction
Truncated Singular Value Decomposition (Truncated SVD) is an unsupervised dimensionality reduction technique that reduces the number of features by retaining only the most important singular values and their corresponding vectors. Unlike Principal Component Analysis (PCA), Truncated SVD can operate directly on sparse matrices without requiring data centering, making it particularly useful for text mining and large-scale machine learning.
Information
๐ฏ Learning Objectives
- Understand Truncated Singular Value Decomposition.
- Learn the mathematics behind Singular Value Decomposition.
- Understand why Truncated SVD is preferred for sparse data.
- Compare Truncated SVD with PCA.
๐ What is Truncated SVD?
Truncated SVD approximates a high-dimensional matrix using a smaller number of singular values and vectors. By keeping only the largest singular values, it preserves the most significant patterns in the data while reducing dimensionality.
| Characteristic | Truncated SVD |
|---|---|
| Learning Type | Unsupervised |
| Based On | Singular Value Decomposition |
| Supports Sparse Data | Yes |
| Centers Data | No |
๐ Key Concepts
| Concept | Description |
|---|---|
| Singular Values | Measure the importance of latent components. |
| Left Singular Vectors | Represent transformed observations. |
| Right Singular Vectors | Represent transformed features. |
| Rank | Number of independent dimensions in the matrix. |
| Low-Rank Approximation | Reduced representation using the most significant components. |
๐ Singular Value Decomposition
Singular Value Decomposition factorizes a matrix into three smaller matrices.
Where:
- X โ Original data matrix.
- U โ Left singular vectors.
- ฮฃ โ Diagonal matrix of singular values.
- Vแต โ Right singular vectors.
Remember
โ๏ธ Truncated SVD Approximation
Instead of using every singular value, Truncated SVD retains only the first k largest singular values and their corresponding vectors.
Where:
- k โ Number of retained components.
- Uโ, ฮฃโ, Vโ โ Reduced matrices.
โ๏ธ How Truncated SVD Works
Construct the original data matrix.
Perform Singular Value Decomposition.
Sort singular values from largest to smallest.
Select the top k singular values.
Construct the low-rank approximation.
Transform the original dataset into the reduced feature space.
๐ณ Truncated SVD Workflow
๐ Explained Variance Ratio
Similar to PCA, Truncated SVD reports the proportion of variance explained by each retained component.
Tip
๐ Truncated SVD vs PCA
| Feature | Truncated SVD | PCA |
|---|---|---|
| Centers Data | No | Yes |
| Supports Sparse Matrices | Excellent | Limited |
| Uses SVD | Yes | Yes |
| Typical Application | Text Mining | General Numerical Data |
| Memory Efficiency | High for Sparse Data | Lower for Sparse Data |
๐ Latent Semantic Analysis (LSA)
One of the most important applications of Truncated SVD is Latent Semantic Analysis (LSA). In NLP, documents are represented as sparse term-document matrices. Truncated SVD reduces these matrices into latent semantic dimensions, allowing similar documents and words to be identified even when they do not share identical vocabulary.
๐๏ธ Important Hyperparameters
| Hyperparameter | Description |
|---|---|
| n_components | Number of retained singular values. |
| algorithm | SVD solver (e.g., randomized or ARPACK). |
| n_iter | Iterations used by randomized SVD. |
| random_state | Controls reproducibility. |
| tol | Tolerance for convergence (ARPACK solver). |
๐ Evaluation Metrics
- Explained Variance Ratio
- Cumulative Explained Variance
- Reconstruction Error
- Downstream Model Performance
โ๏ธ Advantages and Limitations
- Works directly with sparse matrices.
- Efficient for high-dimensional datasets.
- Excellent for NLP and text mining.
- Reduces storage and computational cost.
- Captures latent relationships among features.
- Components are less interpretable than original features.
- Captures only linear relationships.
- Choosing the number of components requires experimentation.
- May lose important information if too many components are discarded.
๐ Real-World Applications
| Application | Purpose |
|---|---|
| ๐ Text Mining | Reduce high-dimensional document vectors. |
| ๐ Search Engines | Improve semantic document retrieval. |
| ๐ค Natural Language Processing | Perform Latent Semantic Analysis. |
| ๐ฌ Recommendation Systems | Reduce sparse user-item matrices. |
| ๐ Information Retrieval | Discover hidden relationships among terms. |
| ๐ Customer Analytics | Compress large sparse behavioral datasets. |
๐ป Practical Example
Truncated SVD Using Scikit-learn
from sklearn.decomposition import TruncatedSVD
from sklearn.feature_extraction.text import TfidfVectorizer
# Sample documents
documents = [
"Machine learning is powerful",
"Artificial intelligence uses machine learning",
"Deep learning improves AI systems",
"Natural language processing uses text data"
]
# Convert text into TF-IDF matrix
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(documents)
# Apply Truncated SVD
svd = TruncatedSVD(
n_components=2,
random_state=42
)
X_reduced = svd.fit_transform(X)
print("Reduced Shape:", X_reduced.shape)
print("Explained Variance Ratio:")
print(svd.explained_variance_ratio_)โ ๏ธ Common Mistakes
- Confusing Truncated SVD with PCA.
- Choosing too few components and losing semantic information.
- Applying PCA instead of Truncated SVD on sparse text matrices.
- Ignoring the explained variance ratio.
- Expecting nonlinear relationships to be captured.