---
id: detect_distribution_type_py_datascience
name: detect_distribution_type
kind: function
lang: py
domain: datascience
version: "1.0.0"
purity: pure
signature: "def detect_distribution_type(values: list[float]) -> dict"
description: "Classifies the shape of a numeric distribution using skewness, excess kurtosis, tail ratio and log-skewness. Returns a type label and raw stats."
tags: [statistics, distribution, classification, skewness, kurtosis, pendiente-usar]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: [math, numpy]
example: |
  from detect_distribution_type import detect_distribution_type
  import numpy as np
  result = detect_distribution_type(np.random.normal(0, 1, 200).tolist())
  # {"type": "normal-ish", "stats": {"n": 200, "skew": ..., ...}}
tested: true
tests:
  - "test_detect_too_few_samples"
  - "test_detect_normal_ish"
  - "test_detect_right_skewed"
  - "test_detect_stats_keys"
  - "test_detect_exactly_30"
test_file_path: "python/functions/datascience/tests/test_detect_distribution_type.py"
file_path: "python/functions/datascience/detect_distribution_type.py"
params:
  - name: values
    desc: "List of numeric values to classify. Minimum 30 for meaningful classification."
output: >
  Dict with "type" (str) and "stats" (dict). Type is one of: normal-ish,
  lognormal-ish, heavy-tail, right-skewed, left-skewed, other, too_few_samples.
  Stats contains: n, skew, kurtosis, tail_ratio, log_skew.
source_repo: "internal:footprint_aurgi"
source_license: "internal-aurgi"
source_file: "aurgi_mapas/generar_pdf_reporte.py:133"
---

## Ejemplo

```python
from detect_distribution_type import detect_distribution_type
import numpy as np

detect_distribution_type(np.random.normal(0, 1, 200).tolist())
# {"type": "normal-ish", "stats": {"n": 200, "skew": 0.03, ...}}

detect_distribution_type([1]*5)
# {"type": "too_few_samples", "stats": {"n": 5}}
```

## Logica de clasificacion

- n < 30 → too_few_samples
- excess kurtosis > 3 → heavy-tail
- |skew| <= 0.5 AND |kurt| <= 1 → normal-ish
- skew > 0.5 AND log_skew cerca de 0 AND tail_ratio > 2 → lognormal-ish
- skew > 0.5 → right-skewed
- skew < -0.5 → left-skewed
- default → other

tail_ratio = p99/p50; log_skew calculado solo si hay >= 30 positivos.
