Entropy¶
Running entropy.
Parameters¶
-
fading_factor – defaults to
1
Fading factor.
-
eps – defaults to
1e-08
Small value that will be added to the denominator to avoid division by zero.
Attributes¶
-
entropy (float)
The running entropy.
-
n (int)
The current number of observations.
-
counter (collections.Counter)
Count the number of times the values have occurred
Examples¶
>>> import math
>>> import random
>>> import numpy as np
>>> from scipy.stats import entropy
>>> from river import stats
>>> def entropy_list(labels, base=None):
... value,counts = np.unique(labels, return_counts=True)
... return entropy(counts, base=base)
>>> SEED = 42 * 1337
>>> random.seed(SEED)
>>> entro = stats.Entropy(fading_factor=1)
>>> list_animal = []
>>> for animal, num_val in zip(['cat', 'dog', 'bird'],[301, 401, 601]):
... list_animal += [animal for i in range(num_val)]
>>> random.shuffle(list_animal)
>>> for animal in list_animal:
... _ = entro.update(animal)
>>> print(f'{entro.get():.6f}')
1.058093
>>> print(f'{entropy_list(list_animal):.6f}')
1.058093
Methods¶
get
Return the current value of the statistic.
update
Update and return the called instance.
Parameters
- x (numbers.Number)