{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "2a56bf88",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "e3a36cec",
            "cell_type": "markdown",
            "source": "To use the distribution class, it must be instantiated using keyword\nparameters corresponding with one of the accepted parameterizations.\n",
            "metadata": {}
        },
        {
            "id": "41c317c6",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import stats\nfrom scipy.stats import Binomial\nX = Binomial(n=10.0, p=0.34)",
            "outputs": []
        },
        {
            "id": "00cb3c1e",
            "cell_type": "markdown",
            "source": "For convenience, the ``plot`` method can be used to visualize the density\nand other functions of the distribution.\n",
            "metadata": {}
        },
        {
            "id": "ca5bd0ce",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.plot()\nplt.show()",
            "outputs": []
        },
        {
            "id": "db272e10",
            "cell_type": "markdown",
            "source": "The support of the underlying distribution is available using the ``support``\nmethod.\n",
            "metadata": {}
        },
        {
            "id": "a23475e0",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.support()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(np.float64(0.0), np.float64(10.0))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ada63114",
            "cell_type": "markdown",
            "source": "The numerical values of parameters associated with all parameterizations\nare available as attributes.\n",
            "metadata": {}
        },
        {
            "id": "abb27daa",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.n, X.p",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(np.float64(10.0), np.float64(0.34))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ba3cb656",
            "cell_type": "markdown",
            "source": "To evaluate the probability density/mass function of the underlying distribution\nat argument ``x=3.0``:\n",
            "metadata": {}
        },
        {
            "id": "4af58e63",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = 3.0\nX.pdf(x), X.pmf(x)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(np.float64(inf), np.float64(0.2572915634331659))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "8634f3d8",
            "cell_type": "markdown",
            "source": "The cumulative distribution function, its complement, and the logarithm\nof these functions are evaluated similarly.\n",
            "metadata": {}
        },
        {
            "id": "c39635d5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "np.allclose(np.exp(X.logccdf(x)), 1 - X.cdf(x))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "02509baf",
            "cell_type": "markdown",
            "source": "There are methods for computing measures of central tendency,\ndispersion, higher moments, and entropy.\n",
            "metadata": {}
        },
        {
            "id": "7cc8b2c9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.mean(), X.median(), X.mode()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(np.float64(3.4000000000000004), np.float64(3.0), np.float64(3.0))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "e22eb0ce",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.variance(), X.standard_deviation()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(np.float64(2.2439999999999998), np.float64(1.4979986648859203))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "e284b273",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.skewness(), X.kurtosis()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(np.float64(0.21361834793382106), np.float64(2.845632798573975))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "039a50fc",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "np.allclose(X.moment(order=6, kind='standardized'),\n            X.moment(order=6, kind='central') / X.variance()**3)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "9e1f0480",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.entropy()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "1.816303869320522"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "4c59d0e5",
            "cell_type": "markdown",
            "source": "Pseudo-random samples can be drawn from\nthe underlying distribution using ``sample``.\n",
            "metadata": {}
        },
        {
            "id": "e2d0dca3",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X.sample(shape=(4,))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([5., 3., 6., 5.])  # may vary"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}