Datalens.ai
← All algorithms

STATISTICS

mode

Return an array of the modal (most common) value in the passed array.

Example of usage

Python API reference included; executable data demonstration pending review.

Usage / limitations

+Use when: Summarise measurements and uncertainty.

−Limitations: Check input requirements, mathematical assumptions and version-specific behaviour before using.

Mathematical formula

See method documentation: implementation and assumptions vary.
Sample dataShow
{
  "variable": "patient_wait_times",
  "domain": "Hospital outpatient waiting-time analysis",
  "feature_names": [
    "wait_minutes"
  ],
  "records": [
    {
      "wait_minutes": 12
    },
    {
      "wait_minutes": 16
    },
    {
      "wait_minutes": 18
    },
    {
      "wait_minutes": 20
    },
    {
      "wait_minutes": 24
    },
    {
      "wait_minutes": 30
    },
    {
      "wait_minutes": 34
    },
    {
      "wait_minutes": 40
    }
  ]
}

Code example (Python)

# DataLens.ai example — mode
# Domain: hospital outpatient waiting-time analysis.
# Sample data are included by Copy input + code + test.
import numpy as np
from scipy.stats import mode

# Extract named waiting-time observations into a numeric array.
values = np.array([row["wait_minutes"] for row in patient_wait_times["records"]], dtype=float)

# Apply this statistical method to the observations.
values_with_repeats = np.concatenate([values,[20,20]]); result = mode(values_with_repeats)

# Verify the calculated statistic against a mathematical property.
assert result.mode == 20 and result.count == 3
print("Expected output verified")