Skip to main content

SVD Time Series Imputer

PyPI version Python versions License: MIT

A Python package for time series imputation using Singular Value Decomposition (SVD) with automatic rank estimation and uncertainty quantification.

Table of Contents

A Python package for time series imputation using SVD with automatic rank estimation, uncertainty quantification, and scikit-learn compatible API.

Installation

PyPI (Recommended):

pip install svd-imputer

From Source (development version):

git clone https://github.com/rhugman/svd_imputer.git
cd svd_imputer
pip install -e .

With Development Dependencies:

pip install -e ".[dev]"

Quick Start

import pandas as pd
import numpy as np
from svd_imputer import Imputer

# Load your time series data (with datetime index)
df = pd.read_csv("your_data.csv", index_col=0, parse_dates=True)

# Simple imputation with automatic rank estimation
imputer = Imputer(data=df, variance_threshold=0.95)
df_imputed = imputer.fit_transform()

# With uncertainty estimation (Multiple Imputation)
df_imputed, df_uncertainty = imputer.fit_transform(return_uncertainty=True, n_imputations=10)
print(f"Average uncertainty: {df_uncertainty.mean().mean():.3f}")

Note: The Imputer class uses a data-centric design where data is provided at initialization and preprocessed once. This ensures consistency across all analyses and eliminates redundant preprocessing operations.

Usage

from svd_imputer import Imputer

# Basic imputation (automatic rank estimation)
imputer = Imputer(data=df, variance_threshold=0.95)
df_imputed = imputer.fit_transform()

# Cross-validation optimization
imputer = Imputer(data=df, rank="auto")
imputer.fit()
print(f"Optimized rank: {imputer.rank_}")

# With uncertainty estimation (Multiple Imputation)
df_imputed, df_uncertainty = imputer.fit_transform(return_uncertainty=True, n_imputations=10)
# df_uncertainty contains standard deviations for each imputed value

# Advanced: model diagnostics
residuals, stats = imputer.calculate_reconstruction_residuals(return_stats=True)
print(f"Reconstruction R²: {stats['r_squared']:.3f}")

Configuration

imputer = Imputer(
    data=df,                    # Input DataFrame (required)
    variance_threshold=0.95,    # Variance threshold for auto rank estimation
    rank=None,                  # None (auto-estimate), int (fixed), or "auto" (optimize)
    max_iters=500,             # Maximum SVD iterations
    tol=1e-4,                  # Convergence tolerance  
    verbose=True               # Enable logging output
)

Examples

Complete examples are available in the examples/ directory:

  • basic_example.ipynb - Basic usage and quick start tutorial
  • augmented_example.ipynb - Extended examples with data agumentation features

How It Works

The algorithm performs iterative SVD imputation with automatic rank estimation:

  1. Preprocessing: Data validation, standardization, and missing value handling
  2. Rank Estimation: Variance threshold, cross-validation, or fixed rank
  3. SVD Imputation: Iterative low-rank approximation until convergence
  4. Uncertainty Estimation: Multiple Imputation (Stochastic SVD) or Monte Carlo validation

API Reference

Main Class

Imputer(data, variance_threshold=0.95, rank=None, max_iters=500, tol=1e-4, verbose=True)

Key Methods

  • fit() / transform() / fit_transform(): Standard sklearn interface
  • estimate_uncertainty(): Monte Carlo validation
  • calculate_reconstruction_residuals(): Model diagnostics
  • project_data() / reconstruct_data(): SVD subspace operations

Requirements

  • Python >= 3.8
  • numpy >= 1.20.0
  • pandas >= 1.3.0
  • scikit-learn >= 1.0.0

Performance Notes

  • Memory: O(n × m) for data size n×m, plus O(min(n,m)²) for SVD decomposition
  • Time Complexity: O(k × min(n,m)³) where k is the number of SVD iterations
  • Recommended Scale: Efficient for datasets up to ~10,000 × 100 dimensions
  • Optimization: SVD components are cached for efficient reuse across operations

Package Status

Current Status: Published on PyPI 🎉

This package is currently in Beta - the core functionality is stable and tested (86 tests passing), but the API may evolve. Suitable for research and development use.

Disclaimer

IMPORTANT: This software is provided "as is" without warranty of any kind. The authors and contributors make no representations or warranties regarding the accuracy, completeness, or validity of the code or its results. Users are solely responsible for validating the appropriateness and correctness of this software for their specific use cases. The authors assume no responsibility or liability for any errors, omissions, or damages arising from the use of this software.

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

Citation

If you use this package in your research, please cite:

@software{svd_time_series_imputer,
  title={SVD Time Series Imputer: A Python Package for Missing Data Imputation},
  author={Rui Hugman},
  year={2025},
  url={https://github.com/rhugman/svd_imputer},
  note={Available on PyPI: https://pypi.org/project/svd-imputer/}
}

Metadata

Release files for svd-imputer 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for svd-imputer 0.2.7
File Size Uploaded
svd_imputer-0.2.7.tar.gz 211.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for svd-imputer 0.2.7
File Interpreter ABI Platform
svd_imputer-0.2.7-py3-none-any.whl Python 3 none any Details

Total release size: 235.5 kB

Release files / svd_imputer-0.2.7.tar.gz

Download URL svd_imputer-0.2.7.tar.gz
Size 211.9 kB
Tags Source
SHA-256 checksum
How to use checksums
abefc0c607606cd5dce0686c2eee2a3b2cdc4a8f30523677e678e169baa93b3c
BLAKE2b-256 checksum
How to use checksums
de556b9de68dcd4f4b24cb26911e592df0b3f28e58693a0b046664dc8c523a21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 5, 2026.

Transparency log

Release files / svd_imputer-0.2.7-py3-none-any.whl

Download URL svd_imputer-0.2.7-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8925ae904e1ad52bf8ac7780cc3ba3481b9573abdcc4949f87d7f89add58b3e
BLAKE2b-256 checksum
How to use checksums
01266444a888636b4c8313902538bdaf171b1a09e0784ce0635d0608e7b6fffa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.7 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page