Browse Source

New translations stats.py (Chinese Simplified)

l10n_v0.2.x
linlin 4 years ago
parent
commit
8078113024
1 changed files with 27 additions and 0 deletions
  1. +27
    -0
      lang/zh/gklearn/utils/stats.py

+ 27
- 0
lang/zh/gklearn/utils/stats.py View File

@@ -0,0 +1,27 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 5 15:12:41 2020

@author: ljia
"""
from collections import Counter
from scipy import stats


def entropy(labels, base=None):
"""Calculate the entropy of a distribution for given list of labels.

Parameters
----------
labels : list
Given list of labels.
base : float, optional
The logarithmic base to use. The default is ``e`` (natural logarithm).

Returns
-------
float
The calculated entropy.
"""
return stats.entropy(list(Counter(labels).values()), base=base)

Loading…
Cancel
Save