Skip to main content

OO For eazy statistics, inspired by `Statistics` class of the lib `deap` but more user-friendly

Project description

Ezstat: Easy statistics

OO For easy statistics, inspired by Statistics class of deap

It is really easy and awesome! Believe me!

Introduction

ezstat is built for easy statistics, esp. for the history of iterations.

Statistics

The main class Statistics just extends dict{str:function} (called statistics dict), function here will act on the object of statistics. The values of dict have not to be a function, if it is a string, then the object of method with the same name is applied.

Frankly, It just borrows the idea from the Statistics class of deap. But unlike the author of deap, I just create it a subclass of dict, need not define strange methods.

See the following example and function _call, the underlying implementation.

Examples

Example:

>>> import numpy as np

>>> T = np.random.random((100,100)) # samples(one hundrand 100D samples)
>>> stat = Statistics({'mean': np.mean, 'max': 'max', 'shape':'shape'}) # create statistics
>>> print(stat(T))
>>> {'mean': 0.5009150557686407, 'max': 0.5748552862392957, 'shape': (100, 100)}

>>> print(stat(T, split=True)) # split the tuple if it needs
>>> {mean': 0.5009150557686407, 'max': 0.5748552862392957, 'shape[0]': 100, 'shape[1]': 100}
# with sub-statistics
s = Statistics({'mean': np.mean,
'extreme': {'max':'max', 'min':np.min},  # as a sub-statistics
'shape':'shape'})
print(s(X))
# dict-valued statistics, equivalent to the above
s = Statistics({'mean': np.mean, 'extreme': lambda x:{'max': np.max(x), 'min': np.min(x)}, 'shape':'shape'})
print(s(X))

#Result: {'mean': 0.49786554518848564, 'extreme[max]': 0.9999761647791217, 'extreme[min]': 0.0001368184546896023, 'shape': (100, 100)}

MappingStatistics

MappingStatistics is a subclass of Statistics. It only copes with iterable object, and maps the obect to an array by funcional attribute key.

Example:

>>> stat = MappingStatistics(key='mean', {'mean':np.mean, 'max':np.max})
>>> print(stat(T))
>>> {'mean': 0.5009150557686407, 'max': 0.5748552862392957}

In the exmaple, 'mean', an attribute of T, maps T to a 1D array.

Advanced Usage

Statistics acts on a list/tuple of objects iteratively, gets a series of results, forming an object of pandas.DataFrame. In fact, it is insprited by Statistics class of third part lib deap. In some case, it collects a list of dicts of the statistics result for a series of objects. It is suggested to transform to DataFrame object.

history = pd.DataFrame(columns=stat.keys())
for obj in objs:
    history = history.append(stat(obj), ignore_index=True)

To Do

  • To define tuple of functions for the value of statistics dict.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ezstat-1.4.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

ezstat-1.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file ezstat-1.4.tar.gz.

File metadata

  • Download URL: ezstat-1.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/19.6.0

File hashes

Hashes for ezstat-1.4.tar.gz
Algorithm Hash digest
SHA256 7d64772c85b0274763c5d03638edd3660c74e336ea28fa8d476f48895d81d142
MD5 4123ace98f54e1470588c4a414f7c5a8
BLAKE2b-256 bec014203ed4482744c452411e768922ecc95867733b8f6d4f11023f75cf0ae2

See more details on using hashes here.

File details

Details for the file ezstat-1.4-py3-none-any.whl.

File metadata

  • Download URL: ezstat-1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/19.6.0

File hashes

Hashes for ezstat-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9dc470e50fb874e7b081ac82ae632e463f99bb68bfa5a00e187e0f8fc8434d88
MD5 62905315dd5fa18e92e7968d2c4b4d78
BLAKE2b-256 c06687726b235c91389792b57909221ea4f4a0947004f9327dd62a8bffe97a8c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page