<p align="center">
<img width=60% src="https://github.com/tfm000/sklarpy/blob/main/media/logo.png?raw=true" alt="SklarPy logo">
</p>
<p align="center">
<a href="https://github.com/tfm000/sklarpy/blob/main/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg"
alt="MIT license"></a>
<a href="https://github.com/tfm000/sklarpy/actions/workflows/tests.yml">
<img src="https://github.com/tfm000/sklarpy/actions/workflows/tests.yml/badge.svg?branch=main"
alt="build"></a>
<a href="https://sklarpy.readthedocs.io/en/latest/?badge=latest">
<img src="https://readthedocs.org/projects/sklarpy/badge/?version=latest"
alt="build"></a>
<a href="https://pepy.tech/project/sklarpy">
<img src="https://static.pepy.tech/personalized-badge/sklarpy?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads"
alt="downloads"></a>
<a href="https://pypi.org/project/sklarpy/">
<img src="https://img.shields.io/badge/Maintained%3F-yes-green.svg"
alt="maintained"></a>
</p>
<p align="center">
<a href="https://pypi.org/project/sklarpy/">
<img src="https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=apple&logoColor=white"
alt="mac os"></a>
<a href="https://pypi.org/project/sklarpy/">
<img src="https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white"
alt="windows"></a>
</p>
SklarPy (pronounced 'Sky-Lar-Pee' or 'Sky-La-Pie') is an open-source software for probability distribution fitting.
It contains useful tools for fitting Copula, Multivariate and Univariate probability distributions.
In addition to over 100 univariate distributions, we implement many multivariate normal mixture distributions and their copulas, including Gaussian, Student-T, Skewed-T and Generalized Hyperbolic distributions.
Named after Sklar's theorem and Abe Sklar, the American mathematician who proved that multivariate cumulative distribution functions can be expressed in terms of copulas and their marginals.
This library has many different possible use cases, ranging from machine learning to finance.
## Read the Docs
Official SklarPy documentation can be found <a href="https://sklarpy.readthedocs.io/en/latest/"> here</a>.
## Table of contents
- [Table of contents](#table_of_contents)
- [Installation](#installation)
- [Examples](#examples)
- [Why we are better](#why-we-are-better)
- [Testing](#testing)
## Installation
SklarPy is available on PyPI and can be installed by running:
```bash
pip install sklarpy
```
## Examples
Here is an example of SklarPy's implementation of the Generalized Hyperbolic Copula model being fitted onto bivariate data.
```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklarpy.copulas import gh_copula
# generating random data
n: int = 1000
obs: np.ndarray = np.full((n, 2), np.nan)
obs[:, 0] = np.random.normal(3,4, size=(n,))
obs[:, 1] = obs[:, 0] + 0.5 * np.random.normal(3, 5, size=(n,))
obvs_df: pd.DataFrame = pd.DataFrame(obs, columns=['Process A', 'Process B'])
# fitting our copula model
fitted_copula = gh_copula.fit(obvs_df)
# printing our fitted copula parameters
print(fitted_copula.copula_params.to_dict)
# printing our fitted marginal distributions
print(fitted_copula.mdists)
# plotting our fit
fitted_copula.pdf_plot(show=False)
fitted_copula.copula_pdf_plot(show=False)
plt.show()
```
```txt
{'lamb': -10.0, 'chi': 4.227038325195731, 'psi': 10.0,
'loc': array([[0.], [0.]]),
'shape': array([[1. , 0.84273015],
[0.84273015, 1.]]),
'gamma': array([[0.99696041], [0.99913161]])}
{0: lognorm(0.02, -203.22, 206.18), 1: lognorm(0.04, -110.89, 115.4)}
```
<p align="center">
<img width=60% src="https://github.com/tfm000/sklarpy/blob/main/media/PDF_Gh_PDF_Plot_Plot.png?raw=true">
<img width=60% src="https://github.com/tfm000/sklarpy/blob/main/media/Copula_PDF_Gh_Copula_PDF_Plot_Plot.png?raw=true">
</p>
Further examples can be found <a href="https://github.com/tfm000/sklarpy/tree/main/examples"> here</a>.
## Why we are better
- Unlike other Python implementations of copulas, we implement more than the Gaussian and Archimedean copulas. A full list of our implementated copula models can be found <a href="https://github.com/tfm000/sklarpy/tree/main/sklarpy/copulas"> here</a>, though it includes many normal mean-variance mixture models as well as Archimedean and non-parametric models.
- We allow for easy parameter fitting of both the univariate marginals and the multivariate copula distribution.
- We allow for easy plotting of all our distributions, allowing you to visualize your models.
- We use scipy.stats as a backend for all our univariate models, meaning as scipy expands and improves their model selection, so will ours!
- We provide multivariate and univariate distributions, in addition to our copula models, meaning SklarPy can act as a one-stop-shop for all probability distribution fitting. A full list of our implemented multivariate distributions can be found <a href="https://github.com/tfm000/sklarpy/tree/main/sklarpy/multivariate"> here</a>.
- We are continuing to expand our library, and are open to suggestions for new models to implement. If you have a model you would like to see implemented, please open an issue on our <a href="https://github.com/tfm000/sklarpy/issues">GitHub page</a>.
## Testing
All tests are written using pytest and cover all user accessible code.
Some tests may be commented out or scaled back if they are likely to cause a memory error when run using github actions, however these have been extensively tested locally across multiple different Python versions and OS.
Raw data
{
"_id": null,
"home_page": "",
"name": "sklarpy",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "Tyler Mitchell <tylerfmitchell1999@gmail.com>",
"keywords": "SklarPy,Sklar,Copula,Copulas,Copulae,Probability,Distribution,Univariate,Bivariate,Multivariate,Joint,CDF,PDF,Modeling,Quantitative,Fitting,SciPy,Statistics,Mathematics,Science,Scientific,Finance,Risk,VaR,Machine Learning,Variables",
"author": "",
"author_email": "Tyler Mitchell <tylerfmitchell1999@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e0/5b/ce563f81966b7819157479c54c31069d24b2ad9332c35555c8c3c370e065/sklarpy-1.0.0.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <img width=60% src=\"https://github.com/tfm000/sklarpy/blob/main/media/logo.png?raw=true\" alt=\"SklarPy logo\">\n</p>\n\n<p align=\"center\">\n <a href=\"https://github.com/tfm000/sklarpy/blob/main/LICENSE\">\n <img src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg\"\n alt=\"MIT license\"></a> \n <a href=\"https://github.com/tfm000/sklarpy/actions/workflows/tests.yml\">\n <img src=\"https://github.com/tfm000/sklarpy/actions/workflows/tests.yml/badge.svg?branch=main\"\n alt=\"build\"></a> \n <a href=\"https://sklarpy.readthedocs.io/en/latest/?badge=latest\">\n <img src=\"https://readthedocs.org/projects/sklarpy/badge/?version=latest\"\n alt=\"build\"></a> \n <a href=\"https://pepy.tech/project/sklarpy\">\n <img src=\"https://static.pepy.tech/personalized-badge/sklarpy?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads\"\n alt=\"downloads\"></a> \n <a href=\"https://pypi.org/project/sklarpy/\">\n <img src=\"https://img.shields.io/badge/Maintained%3F-yes-green.svg\"\n alt=\"maintained\"></a>\n</p>\n\n<p align=\"center\">\n <a href=\"https://pypi.org/project/sklarpy/\">\n <img src=\"https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=apple&logoColor=white\"\n alt=\"mac os\"></a>\n <a href=\"https://pypi.org/project/sklarpy/\">\n <img src=\"https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white\"\n alt=\"windows\"></a>\n</p>\n\n\nSklarPy (pronounced 'Sky-Lar-Pee' or 'Sky-La-Pie') is an open-source software for probability distribution fitting.\nIt contains useful tools for fitting Copula, Multivariate and Univariate probability distributions.\nIn addition to over 100 univariate distributions, we implement many multivariate normal mixture distributions and their copulas, including Gaussian, Student-T, Skewed-T and Generalized Hyperbolic distributions.\nNamed after Sklar's theorem and Abe Sklar, the American mathematician who proved that multivariate cumulative distribution functions can be expressed in terms of copulas and their marginals.\n\nThis library has many different possible use cases, ranging from machine learning to finance.\n\n## Read the Docs\nOfficial SklarPy documentation can be found <a href=\"https://sklarpy.readthedocs.io/en/latest/\"> here</a>.\n\n## Table of contents\n\n- [Table of contents](#table_of_contents)\n- [Installation](#installation)\n- [Examples](#examples)\n- [Why we are better](#why-we-are-better)\n- [Testing](#testing)\n\n## Installation\nSklarPy is available on PyPI and can be installed by running:\n\n```bash\npip install sklarpy\n```\n\n## Examples\nHere is an example of SklarPy's implementation of the Generalized Hyperbolic Copula model being fitted onto bivariate data.\n\n```python\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklarpy.copulas import gh_copula\n\n# generating random data\nn: int = 1000\nobs: np.ndarray = np.full((n, 2), np.nan)\nobs[:, 0] = np.random.normal(3,4, size=(n,))\nobs[:, 1] = obs[:, 0] + 0.5 * np.random.normal(3, 5, size=(n,))\nobvs_df: pd.DataFrame = pd.DataFrame(obs, columns=['Process A', 'Process B'])\n\n# fitting our copula model\nfitted_copula = gh_copula.fit(obvs_df)\n\n# printing our fitted copula parameters\nprint(fitted_copula.copula_params.to_dict)\n\n# printing our fitted marginal distributions\nprint(fitted_copula.mdists)\n\n# plotting our fit\nfitted_copula.pdf_plot(show=False)\nfitted_copula.copula_pdf_plot(show=False)\nplt.show()\n```\n```txt\n{'lamb': -10.0, 'chi': 4.227038325195731, 'psi': 10.0, \n 'loc': array([[0.], [0.]]), \n 'shape': array([[1. , 0.84273015], \n [0.84273015, 1.]]), \n 'gamma': array([[0.99696041], [0.99913161]])}\n\n{0: lognorm(0.02, -203.22, 206.18), 1: lognorm(0.04, -110.89, 115.4)}\n```\n<p align=\"center\">\n <img width=60% src=\"https://github.com/tfm000/sklarpy/blob/main/media/PDF_Gh_PDF_Plot_Plot.png?raw=true\">\n <img width=60% src=\"https://github.com/tfm000/sklarpy/blob/main/media/Copula_PDF_Gh_Copula_PDF_Plot_Plot.png?raw=true\">\n</p>\n\n\nFurther examples can be found <a href=\"https://github.com/tfm000/sklarpy/tree/main/examples\"> here</a>.\n\n## Why we are better\n- Unlike other Python implementations of copulas, we implement more than the Gaussian and Archimedean copulas. A full list of our implementated copula models can be found <a href=\"https://github.com/tfm000/sklarpy/tree/main/sklarpy/copulas\"> here</a>, though it includes many normal mean-variance mixture models as well as Archimedean and non-parametric models.\n- We allow for easy parameter fitting of both the univariate marginals and the multivariate copula distribution.\n- We allow for easy plotting of all our distributions, allowing you to visualize your models.\n- We use scipy.stats as a backend for all our univariate models, meaning as scipy expands and improves their model selection, so will ours!\n- We provide multivariate and univariate distributions, in addition to our copula models, meaning SklarPy can act as a one-stop-shop for all probability distribution fitting. A full list of our implemented multivariate distributions can be found <a href=\"https://github.com/tfm000/sklarpy/tree/main/sklarpy/multivariate\"> here</a>.\n- We are continuing to expand our library, and are open to suggestions for new models to implement. If you have a model you would like to see implemented, please open an issue on our <a href=\"https://github.com/tfm000/sklarpy/issues\">GitHub page</a>.\n\n## Testing\nAll tests are written using pytest and cover all user accessible code.\nSome tests may be commented out or scaled back if they are likely to cause a memory error when run using github actions, however these have been extensively tested locally across multiple different Python versions and OS.\n",
"bugtrack_url": null,
"license": "",
"summary": "Copula, Multivariate and Univariate probability distribution fitting in Python.",
"version": "1.0.0",
"project_urls": {
"Bug Reports": "https://github.com/tfm000/sklarpy/issues",
"Homepage": "https://github.com/tfm000/sklarpy",
"Source": "https://github.com/tfm000/sklarpy"
},
"split_keywords": [
"sklarpy",
"sklar",
"copula",
"copulas",
"copulae",
"probability",
"distribution",
"univariate",
"bivariate",
"multivariate",
"joint",
"cdf",
"pdf",
"modeling",
"quantitative",
"fitting",
"scipy",
"statistics",
"mathematics",
"science",
"scientific",
"finance",
"risk",
"var",
"machine learning",
"variables"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f18f789880a28d706a71d3916fafc1953021a16045d4c0d571d1fbba65bb4365",
"md5": "0d929ab01b3953697831a8756dd33219",
"sha256": "bd151ba2378d48203053a2cbb9ccf91d210f9e1f29767de9afe304c1b5c92fd6"
},
"downloads": -1,
"filename": "sklarpy-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0d929ab01b3953697831a8756dd33219",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 179342,
"upload_time": "2023-12-04T18:37:17",
"upload_time_iso_8601": "2023-12-04T18:37:17.322480Z",
"url": "https://files.pythonhosted.org/packages/f1/8f/789880a28d706a71d3916fafc1953021a16045d4c0d571d1fbba65bb4365/sklarpy-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e05bce563f81966b7819157479c54c31069d24b2ad9332c35555c8c3c370e065",
"md5": "331556b09888051b79c5802f377d5121",
"sha256": "feec5f73292236348f9ea381007a66b17fb919ded567efddc644dad49522560b"
},
"downloads": -1,
"filename": "sklarpy-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "331556b09888051b79c5802f377d5121",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 128839,
"upload_time": "2023-12-04T18:37:19",
"upload_time_iso_8601": "2023-12-04T18:37:19.549750Z",
"url": "https://files.pythonhosted.org/packages/e0/5b/ce563f81966b7819157479c54c31069d24b2ad9332c35555c8c3c370e065/sklarpy-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-04 18:37:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tfm000",
"github_project": "sklarpy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "sklarpy"
}