Dataset viewer 文档

探索分割数据的统计信息

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

探索分割数据的统计信息

dataset viewer 提供了一个 /statistics 端点,用于获取为请求的数据集预计算的一些基本统计信息。这将使您快速了解数据的分布情况。

目前,统计信息仅针对具有 Parquet 导出的数据集计算。

/statistics 端点需要三个查询参数

  • dataset: 数据集名称,例如 nyu-mll/glue
  • config: subset 名称,例如 cola
  • split: split 名称,例如 train

让我们获取 nyu-mll/glue 数据集、cola subset、train split 的一些统计信息

Python
JavaScript
cURL
import requests
headers = {"Authorization": f"Bearer {API_TOKEN}"}
API_URL = "https://datasets-server.huggingface.co/statistics?dataset=nyu-mll/glue&config=cola&split=train"
def query():
    response = requests.get(API_URL, headers=headers)
    return response.json()
data = query()

响应 JSON 包含三个键

  • num_examples - split 中的样本数,如果数据集大于 5GB,则为数据的第一块中的样本数(请参阅下面的 partial 字段)。
  • statistics - 每个列的统计信息字典列表,每个字典有三个键:column_namecolumn_typecolumn_statisticscolumn_statistics 的内容取决于列类型,有关更多详细信息,请参阅按数据类型的响应结构
  • partial - 如果统计信息是在前 5 GB 数据上计算的,而不是在完整 split 上计算的,则为 true,否则为 false
{
  "num_examples": 8551,
  "statistics": [
    {
      "column_name": "idx",
      "column_type": "int",
      "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0,
        "min": 0,
        "max": 8550,
        "mean": 4275,
        "median": 4275,
        "std": 2468.60541,
        "histogram": {
          "hist": [
            856,
            856,
            856,
            856,
            856,
            856,
            856,
            856,
            856,
            847
          ],
          "bin_edges": [
            0,
            856,
            1712,
            2568,
            3424,
            4280,
            5136,
            5992,
            6848,
            7704,
            8550
          ]
        }
      }
    },
    {
      "column_name": "label",
      "column_type": "class_label",
      "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0,
        "no_label_count": 0,
        "no_label_proportion": 0,
        "n_unique": 2,
        "frequencies": {
          "unacceptable": 2528,
          "acceptable": 6023
        }
      }
    },
    {
      "column_name": "sentence",
      "column_type": "string_text",
      "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0,
        "min": 6,
        "max": 231,
        "mean": 40.70074,
        "median": 37,
        "std": 19.14431,
        "histogram": {
          "hist": [
            2260,
            4512,
            1262,
            380,
            102,
            26,
            6,
            1,
            1,
            1
          ],
          "bin_edges": [
            6,
            29,
            52,
            75,
            98,
            121,
            144,
            167,
            190,
            213,
            231
          ]
        }
      }
    }
  ],
  "partial": false
}

按数据类型的响应结构

目前,统计信息支持字符串、浮点数和整数、列表、日期时间、音频和图像数据,以及 datasets.ClassLabel 特征类型(来自 datasets 库)。

响应中的 column_type 可以是以下值之一

  • class_label - 对于表示分类数据的 datasets.ClassLabel 特征
  • float - 对于浮点数据类型
  • int - 对于整数数据类型
  • bool - 对于布尔数据类型
  • string_label - 对于被视为类别的字符串数据类型(见下文)
  • string_text - 对于不表示类别的字符串数据类型(见下文)
  • list - 对于任何其他数据类型的列表(包括列表)
  • audio - 对于音频数据
  • image - 对于图像数据
  • datetime - 对于日期时间数据

class_label

此类型表示编码为 ClassLabel 特征的分类数据。计算以下指标

  • null 值的数量和比例
  • 没有标签的值的数量和比例
  • 唯一值的数量(排除 nullno label
  • 每个标签的值计数(排除 nullno label
示例

{
  "column_name": "label",
  "column_type": "class_label",
  "column_statistics": {
    "nan_count": 0,
    "nan_proportion": 0,
    "no_label_count": 0,
    "no_label_proportion": 0,
    "n_unique": 2,
    "frequencies": {
      "unacceptable": 2528,
      "acceptable": 6023
    }
  }
}

float

以下指标针对浮点数据类型返回

  • 最小值、最大值、平均值、中位数和标准差值
  • nullNaN 值的数量和比例(NaN 值被视为 null
  • 具有 10 个 bins 的直方图
示例

{
  "column_name": "clarity",
  "column_type": "float",
  "column_statistics": {
    "nan_count": 0,
    "nan_proportion": 0,
    "min": 0,
    "max": 2,
    "mean": 1.67206,
    "median": 1.8,
    "std": 0.38714,
    "histogram": {
      "hist": [
        17,
        12,
        48,
        52,
        135,
        188,
        814,
        15,
        1628,
        2048
      ],
      "bin_edges": [
        0,
        0.2,
        0.4,
        0.6,
        0.8,
        1,
        1.2,
        1.4,
        1.6,
        1.8,
        2
      ]
    }
  }
}

int

以下指标针对整数数据类型返回

  • 最小值、最大值、平均值、中位数和标准差值
  • null 值的数量和比例
  • 具有小于或等于 10 个 bins 的直方图
示例

{
    "column_name": "direction",
    "column_type": "int",
    "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0.0,
        "min": 0,
        "max": 1,
        "mean": 0.49925,
        "median": 0.0,
        "std": 0.5,
        "histogram": {
            "hist": [
                50075,
                49925
            ],
            "bin_edges": [
                0,
                1,
                1
            ]
        }
    }
}

bool

以下指标针对布尔数据类型返回

  • null 值的数量和比例
  • 'True''False' 值的值计数
示例

{
  "column_name": "penalty",
  "column_type": "bool",
  "column_statistics":
    {
        "nan_count": 3,
        "nan_proportion": 0.15,
        "frequencies": {
            "False": 7,
            "True": 10
        }
    }
}

string_label

如果请求的 split 中字符串列的唯一值比例小于或等于 0.2,且唯一值数量小于 1000,或者如果唯一值数量小于或等于 10(与比例无关),则认为它是一个类别。返回以下指标

  • null 值的数量和比例
  • 唯一值的数量(排除 null
  • 每个标签的值计数(排除 null
示例

{
  "column_name": "answerKey",
  "column_type": "string_label",
  "column_statistics": {
    "nan_count": 0,
    "nan_proportion": 0,
    "n_unique": 4,
    "frequencies": {
      "D": 1221,
      "C": 1146,
      "A": 1378,
      "B": 1212
    }
  }
}

string_text

如果字符串列不满足被视为 string_label 的条件,则认为它是一个包含文本的列,并且响应包含按字符数计算的文本长度的统计信息。计算以下指标

  • 文本长度的最小值、最大值、平均值、中位数和标准差
  • null 值的数量和比例
  • 具有 10 个 bins 的文本长度直方图
示例

{
  "column_name": "sentence",
  "column_type": "string_text",
  "column_statistics": {
    "nan_count": 0,
    "nan_proportion": 0,
    "min": 6,
    "max": 231,
    "mean": 40.70074,
    "median": 37,
    "std": 19.14431,
    "histogram": {
      "hist": [
        2260,
        4512,
        1262,
        380,
        102,
        26,
        6,
        1,
        1,
        1
      ],
      "bin_edges": [
        6,
        29,
        52,
        75,
        98,
        121,
        144,
        167,
        190,
        213,
        231
      ]
    }
  }
}

list

对于列表,计算其长度的分布。返回以下指标

  • 列表长度的最小值、最大值、平均值、中位数和标准差
  • null 值的数量和比例
  • 具有最多 10 个 bins 的列表长度直方图
示例

{
    "column_name": "chat_history",
    "column_type": "list",
    "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0.0,
        "min": 1,
        "max": 3,
        "mean": 1.01741,
        "median": 1.0,
        "std": 0.13146,
        "histogram": {
            "hist": [
                11177,
                196,
                1
            ],
            "bin_edges": [
                1,
                2,
                3,
                3
            ]
        }
    }
}

请注意,不支持列表字典。

audio

对于音频数据,计算音频文件时长的分布。返回以下指标

  • 音频文件时长的最小值、最大值、平均值、中位数和标准差
  • null 值的数量和比例
  • 具有 10 个 bins 的音频文件时长直方图
示例

{
    "column_name": "audio",
    "column_type": "audio",
    "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0,
        "min": 1.02,
        "max": 15,
        "mean": 13.93042,
        "median": 14.77,
        "std": 2.63734,
        "histogram": {
            "hist": [
                32,
                25,
                18,
                24,
                22,
                17,
                18,
                19,
                55,
                1770
            ],
            "bin_edges": [
                1.02,
                2.418,
                3.816,
                5.214,
                6.612,
                8.01,
                9.408,
                10.806,
                12.204,
                13.602,
                15
            ]
        }
    }
}

image

对于图像数据,计算图像宽度的分布。返回以下指标

  • 图像文件宽度的最小值、最大值、平均值、中位数和标准差
  • null 值的数量和比例
  • 具有 10 个 bins 的图像宽度直方图
示例

{
    "column_name": "image",
    "column_type": "image",
    "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0.0,
        "min": 256,
        "max": 873,
        "mean": 327.99339,
        "median": 341.0,
        "std": 60.07286,
        "histogram": {
            "hist": [
                1734,
                1637,
                1326,
                121,
                10,
                3,
                1,
                3,
                1,
                2
            ],
            "bin_edges": [
                256,
                318,
                380,
                442,
                504,
                566,
                628,
                690,
                752,
                814,
                873
            ]
        }
    }
}

datetime

计算日期时间的分布。返回以下指标

  • 以字符串形式表示的日期时间的最小值、最大值、平均值、中位数和标准差,精度高达秒
  • null 值的数量和比例
  • 具有 10 个 bins 的日期时间直方图
示例

{
    "column_name": "date",
    "column_type": "datetime",
    "column_statistics": {
        "nan_count": 0,
        "nan_proportion": 0.0,
        "min": "2013-05-18 04:54:11",
        "max": "2013-06-20 10:01:41",
        "mean": "2013-05-27 18:03:39",
        "median": "2013-05-23 11:55:50",
        "std": "11 days, 4:57:32.322450",
        "histogram": {
            "hist": [
                318776,
                393036,
                173904,
                0,
                0,
                0,
                0,
                0,
                0,
                206284
            ],
            "bin_edges": [
                "2013-05-18 04:54:11",
                "2013-05-21 12:36:57",
                "2013-05-24 20:19:43",
                "2013-05-28 04:02:29",
                "2013-05-31 11:45:15",
                "2013-06-03 19:28:01",
                "2013-06-07 03:10:47",
                "2013-06-10 10:53:33",
                "2013-06-13 18:36:19",
                "2013-06-17 02:19:05",
                "2013-06-20 10:01:41"
            ]
        }
    }
}

< > 在 GitHub 上更新