Skip to content
Back to skills

Estimate Online Covariance

ASecurity

Estimate a covariance / correlation / precision matrix incrementally with precise. Use when data arrives as a stream and you want the matrix updated per observation, or when you want an online (partial_fit) drop-in for sklearn.covariance, which is batch-only.

  • 334 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 1, 2026
toolspythongobash

Works with

  • cli

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 1, 2026

npx -y skills add microprediction/precise --skill estimate-online-covariance --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Estimate Online Covariance?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Estimate Online Covariance
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/microprediction-estimate-online-covariance/badge)](https://www.skillsdirectory.com/skills/microprediction-estimate-online-covariance)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: estimate-online-covariance
description: Estimate a covariance / correlation / precision matrix incrementally with precise. Use when data arrives as a stream and you want the matrix updated per observation, or when you want an online (partial_fit) drop-in for sklearn.covariance, which is batch-only.
---

# Estimate online covariance with precise

`precise` provides sklearn-style estimators with a single `partial_fit` contract. Pure numpy.

```bash
pip install precise
```

## The pattern

```python
import numpy as np
from precise import EwaCovariance        # exponentially weighted; recency-biased

est = EwaCovariance(r=0.05)              # r in (0,1]; larger = faster forgetting
for y in stream:                         # y is a 1-D array (one observation)
    est.partial_fit(y)

est.covariance_     # (d, d) ndarray, symmetric and PSD by construction
est.correlation_    # unit-diagonal correlation
est.precision_      # inverse covariance (when well-conditioned)
est.location_       # running mean
est.n_samples_      # observations seen
```

`fit(X)` is the batch drop-in (`X` is 2-D, rows = observations); it resets then replays rows, so
it matches `sklearn.covariance`'s call shape.

## Choosing the class

`all_estimators()` lists every estimator; `estimator_from_name("LedoitWolfCovariance")` looks one up.
Sensible defaults by situation:

- general / recency-weighted: `EwaCovariance(r=...)`
- many variables relative to samples (p/n large) or ill-conditioned: `LedoitWolfCovariance`, `OASCovariance`, `ShrunkCovariance`, `FactorCovariance`
- heavy tails / outliers: `HuberCovariance`, `TylerCovariance`
- regime changes: `AdaptiveEwaCovariance`, `DCCCovariance`
- you don't know: use the **choose-covariance-estimator** skill (`suggest(X)`).

## Notes

- All estimators are truly online — constant work per observation, no growing buffers.
- State is a JSON-able dict: `est.get_state()` / `est.set_state(s)` for mid-stream checkpointing.
- `covariance_` is always symmetric PSD; don't hand-symmetrize or clip it yourself.
- Named series with a changing universe? Use the **keyed-dynamic-universe** skill instead.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.