VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-reduce-dimentionality-on-sparse-matrix-in-python/

⇱ How to reduce dimensionality on Sparse Matrix in Python? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to reduce dimensionality on Sparse Matrix in Python?

Last Updated : 7 Jul, 2025

In real world applications such as Natural Language Processing or image processing, data is often represented as large matrices that contain mostly zeros called as sparse matrices. Working with this high dimensional data can be computationally expensive and memory intensive. To handle this more efficiently, dimensionality reduction techniques is applied means shrinking the sparse matrix into a lower dimensional form while preserving most important features.

In Python, a common way to do this is:

  • Converting data into a sparse format like CSR (Compressed Sparse Row).
  • Then, applying dimensionality reduction methods such as Truncated Singular Value Decomposition (TruncatedSVD) using the scikit-learn library.

Let's understand this with an Example.

Example

This Example demonstrates dimensionality reduction of a sparse matrix using TruncatedSVD. It loads the digits dataset, standardizes it, converts it to a CSR sparse format and then reduces the number of features from 64 to 10 while preserving essential information.

Output

πŸ‘ data_and_stnddata
Dataset and Standarized Data
πŸ‘ sparse_and_transfmatrix
Sparse Representation and Transformed Matrix

Verifying Dimensionality Reduction

After applying TruncatedSVD, below code prints original number of features and the reduced number of features to confirm that dimensionality reduction has been successfully applied.

Output

πŸ‘ dim_reductionOutput

It shows how TruncatedSVD effectively reduced the dataset’s features from 64 to 10.

Related Articles

Comment
Article Tags: