Skip to content
Back to skills

Power Divergence

ASecurity

Compute the power_divergence metric — provided by scipy.stats. Use when the user has predictions and ground-truth and needs to compute power_divergence, or asks how to score with power_divergence.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 11, 2026
documentationpythongo

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill power-divergence --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Power Divergence?

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

Security grade badge for Power Divergence
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-power-divergence/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-power-divergence)

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: power-divergence
description: Compute the power_divergence metric — provided by scipy.stats. Use when the user has predictions and ground-truth and needs to compute power_divergence, or asks how to score with power_divergence.
metadata:
  skill_kind: metric
  source_lib: scipy.stats
  import_path: scipy.stats.power_divergence
  source: library_introspection
---

# power-divergence

> Metric `power_divergence` from `scipy.stats` (scipy.stats.power_divergence)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with power_divergence, or
mentions `scipy.stats.power_divergence` directly, or wants the standard scipy.stats implementation.

## Reference signature

```python
from scipy.stats import power_divergence

# power_divergence(f_obs, f_exp=None, ddof=0, axis=0, lambda_=None, *, nan_policy='propagate', keepdims=False)
```

## Library docstring

```
Cressie-Read power divergence statistic and goodness of fit test.

This function tests the null hypothesis that the categorical data
has the given frequencies, using the Cressie-Read power divergence
statistic.

Parameters
----------
f_obs : array_like
    Observed frequencies in each category.
f_exp : array_like, optional
    Expected frequencies in each category.  By default the categories are
    assumed to be equally likely.
ddof : int, optional
    "Delta degrees of freedom": adjustment to the degrees of freedom
    for the p-value.  The p-value is computed using a chi-squared
    distribution with ``k - 1 - ddof`` degrees of freedom, where `k`
    is the number of observed frequencies.  The default value of `ddof`
    is 0.
axis : int or None, default: 0
    If an int, the axis of the input along which to compute the statistic.
    The statistic of each axis-slice (e.g. row) of the input will appear in a
    corresponding element of the output.
    If ``None``, the input will be raveled before computing the statistic.
lambda_ : float or str, optional
    The power in the Cressie-Read power divergence statistic.  The default
    is 1.  For convenience, `lambda_` may be assigned one of the following
    strings, in which case the corresponding numerical value is used:

    * ``"pearson"`` (value 1)
        Pearson's chi-squared statistic. In this case, the function is
        equivalent to `chisquare`.
    * ``"log-likelihood"`` (value 0)
        Log-likelihood ratio. Also known as the G-test [3]_.
    * ``"freeman-tukey"`` (value -1/2)
        Freeman-Tukey statistic.
    * ``"mod-log-likelihood"`` (value -1)
        Modified log-likelihood ratio.
    * ``"neyman"`` (value -2)
        Neyman's statistic.
    * ``"cressie-read"`` (value 2/3)
        The power recommended in [5]_.
nan_policy : {'propagate', 'omit', 'raise'}
    Defines how to handle input NaNs.

    - ``propagate``: if a NaN is present in the axis slice (e.g. row) along
      which the  statistic is computed, the corresponding entry of the output
      will be NaN.
    - ``omit``: NaNs will be omitted when performing the calculation.
      If insufficient data remains in the axis slice along 
```

## Quick recipe

```python
import scipy.stats as _m
score = _m.power_divergence(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

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.