# Ezstat: Easy statistics
OO For easy statistics, inspired by `Statistics` class of [deap](https://deap.readthedocs.io/en/master/index.html)
It is really easy and awesome! Believe me!
![](logo.jpg)
## 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](https://deap.readthedocs.io/en/master/index.html). 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:
```python
>>> 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}
```
```python
# 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:
```python
>>> 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](https://deap.readthedocs.io/en/master/index.html). 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.
```python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/Freakwill/ezstat",
"name": "ezstat",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "Statistics,Genetic Algorithm",
"author": "William Song",
"author_email": "30965609+Freakwill@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/82/c2/697b6ac2210d04977b0381b329619dc060508f18a7d44616017fd99528d7/ezstat-2.3.tar.gz",
"platform": null,
"description": "# Ezstat: Easy statistics\n\n\n\nOO For easy statistics, inspired by `Statistics` class of [deap](https://deap.readthedocs.io/en/master/index.html)\n\nIt is really easy and awesome! Believe me!\n\n![](logo.jpg)\n\n## Introduction\n\n`ezstat` is built for easy statistics, esp. for the history of iterations.\n\n### Statistics\nThe 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.\n\nFrankly, It just borrows the idea from the `Statistics` class of [deap](https://deap.readthedocs.io/en/master/index.html). But unlike the author of deap, I just create it a subclass of dict, need not define strange methods.\n\nSee the following example and function `_call`, the underlying implementation.\n\n### Examples\n\nExample:\n\n```python\n>>> import numpy as np\n\n>>> T = np.random.random((100,100)) # samples(one hundrand 100D samples)\n>>> stat = Statistics({'mean': np.mean, 'max': 'max', 'shape':'shape'}) # create statistics\n>>> print(stat(T))\n>>> {'mean': 0.5009150557686407, 'max': 0.5748552862392957, 'shape': (100, 100)}\n\n>>> print(stat(T, split=True)) # split the tuple if it needs\n>>> {mean': 0.5009150557686407, 'max': 0.5748552862392957, 'shape[0]': 100, 'shape[1]': 100}\n```\n\n```python\n# with sub-statistics\ns = Statistics({'mean': np.mean,\n'extreme': {'max':'max', 'min':np.min}, # as a sub-statistics\n'shape':'shape'})\nprint(s(X))\n# dict-valued statistics, equivalent to the above\ns = Statistics({'mean': np.mean, 'extreme': lambda x:{'max': np.max(x), 'min': np.min(x)}, 'shape':'shape'})\nprint(s(X))\n\n#Result: {'mean': 0.49786554518848564, 'extreme[max]': 0.9999761647791217, 'extreme[min]': 0.0001368184546896023, 'shape': (100, 100)}\n```\n\n### MappingStatistics\n`MappingStatistics` is a subclass of `Statistics`. It only copes with iterable object, and maps the obect to an array by funcional attribute `key`.\n\nExample:\n\n```python\n>>> stat = MappingStatistics(key='mean', {'mean':np.mean, 'max':np.max})\n>>> print(stat(T))\n>>> {'mean': 0.5009150557686407, 'max': 0.5748552862392957}\n```\n\nIn the exmaple, 'mean', an attribute of T, maps T to a 1D array.\n\n## Advanced Usage\n\n`Statistics` acts on a list/tuple of objects iteratively, gets a series of results,\nforming an object of `pandas.DataFrame`. In fact, it is insprited by `Statistics` class of third part lib [deap](https://deap.readthedocs.io/en/master/index.html). 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.\n\n```python\nhistory = pd.DataFrame(columns=stat.keys())\nfor obj in objs:\n history = history.append(stat(obj), ignore_index=True)\n```\n\n## To Do\n\n- [ ] To define tuple of functions for the value of statistics dict.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "OOP For eazy statistics, inspired by `Statistics` class of the lib `deap` but more user-friendly",
"version": "2.3",
"project_urls": {
"Homepage": "https://github.com/Freakwill/ezstat",
"Repository": "https://github.com/Freakwill/ezstat"
},
"split_keywords": [
"statistics",
"genetic algorithm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cb5dddfa89a7311bb0860c26ec291060423275138f3221c5466f2ee98afd2146",
"md5": "89b469dae731e1ef7a834d4f83f48107",
"sha256": "8356ee125edeab9b45d19c4c9772cca77c13031623894d1f897c9abc073930bb"
},
"downloads": -1,
"filename": "ezstat-2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "89b469dae731e1ef7a834d4f83f48107",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 4784,
"upload_time": "2023-12-05T06:12:47",
"upload_time_iso_8601": "2023-12-05T06:12:47.159828Z",
"url": "https://files.pythonhosted.org/packages/cb/5d/ddfa89a7311bb0860c26ec291060423275138f3221c5466f2ee98afd2146/ezstat-2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82c2697b6ac2210d04977b0381b329619dc060508f18a7d44616017fd99528d7",
"md5": "1e8c2821e78a22f65efc9ffe5acb7f71",
"sha256": "520fec56361ea1df42ed2804b2272a37e0f745f390520690bf1cc2e04338cbc6"
},
"downloads": -1,
"filename": "ezstat-2.3.tar.gz",
"has_sig": false,
"md5_digest": "1e8c2821e78a22f65efc9ffe5acb7f71",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 4597,
"upload_time": "2023-12-05T06:12:49",
"upload_time_iso_8601": "2023-12-05T06:12:49.430289Z",
"url": "https://files.pythonhosted.org/packages/82/c2/697b6ac2210d04977b0381b329619dc060508f18a7d44616017fd99528d7/ezstat-2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-05 06:12:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Freakwill",
"github_project": "ezstat",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ezstat"
}