| 1 |
import sys |
| 2 |
from _typeshed import SupportsRichComparisonT |
| 3 |
from collections.abc import Callable, Hashable, Iterable, Sequence, Sized |
| 4 |
from decimal import Decimal |
| 5 |
from fractions import Fraction |
| 6 |
from typing import Literal, NamedTuple, Protocol, SupportsFloat, SupportsIndex, TypeVar, type_check_only |
| 7 |
from typing_extensions import Self, TypeAlias |
| 8 |
|
| 9 |
__all__ = [ |
| 10 |
"StatisticsError", |
| 11 |
"fmean", |
| 12 |
"geometric_mean", |
| 13 |
"mean", |
| 14 |
"harmonic_mean", |
| 15 |
"pstdev", |
| 16 |
"pvariance", |
| 17 |
"stdev", |
| 18 |
"variance", |
| 19 |
"median", |
| 20 |
"median_low", |
| 21 |
"median_high", |
| 22 |
"median_grouped", |
| 23 |
"mode", |
| 24 |
"multimode", |
| 25 |
"NormalDist", |
| 26 |
"quantiles", |
| 27 |
] |
| 28 |
|
| 29 |
if sys.version_info >= (3, 10): |
| 30 |
__all__ += ["covariance", "correlation", "linear_regression"] |
| 31 |
if sys.version_info >= (3, 13): |
| 32 |
__all__ += ["kde", "kde_random"] |
| 33 |
|
| 34 |
|
| 35 |
_Number: TypeAlias = float | Decimal | Fraction |
| 36 |
_NumberT = TypeVar("_NumberT", float, Decimal, Fraction) |
| 37 |
|
| 38 |
|
| 39 |
_HashableT = TypeVar("_HashableT", bound=Hashable) |
| 40 |
|
| 41 |
|
| 42 |
_Seed: TypeAlias = int | float | str | bytes | bytearray |
| 43 |
|
| 44 |
|
| 45 |
_T_co = TypeVar("_T_co", covariant=True) |
| 46 |
|
| 47 |
@type_check_only |
| 48 |
class _SizedIterable(Iterable[_T_co], Sized, Protocol[_T_co]): ... |
| 49 |
|
| 50 |
class StatisticsError(ValueError): ... |
| 51 |
|
| 52 |
if sys.version_info >= (3, 11): |
| 53 |
def fmean(data: Iterable[SupportsFloat], weights: Iterable[SupportsFloat] | None = None) -> float: ... |
| 54 |
|
| 55 |
else: |
| 56 |
def fmean(data: Iterable[SupportsFloat]) -> float: ... |
| 57 |
|
| 58 |
def geometric_mean(data: Iterable[SupportsFloat]) -> float: ... |
| 59 |
def mean(data: Iterable[_NumberT]) -> _NumberT: ... |
| 60 |
|
| 61 |
if sys.version_info >= (3, 10): |
| 62 |
def harmonic_mean(data: Iterable[_NumberT], weights: Iterable[_Number] | None = None) -> _NumberT: ... |
| 63 |
|
| 64 |
else: |
| 65 |
def harmonic_mean(data: Iterable[_NumberT]) -> _NumberT: ... |
| 66 |
|
| 67 |
def median(data: Iterable[_NumberT]) -> _NumberT: ... |
| 68 |
def median_low(data: Iterable[SupportsRichComparisonT]) -> SupportsRichComparisonT: ... |
| 69 |
def median_high(data: Iterable[SupportsRichComparisonT]) -> SupportsRichComparisonT: ... |
| 70 |
|
| 71 |
if sys.version_info >= (3, 11): |
| 72 |
def median_grouped(data: Iterable[SupportsFloat], interval: SupportsFloat = 1.0) -> float: ... |
| 73 |
|
| 74 |
else: |
| 75 |
def median_grouped(data: Iterable[_NumberT], interval: _NumberT | float = 1) -> _NumberT | float: ... |
| 76 |
|
| 77 |
def mode(data: Iterable[_HashableT]) -> _HashableT: ... |
| 78 |
def multimode(data: Iterable[_HashableT]) -> list[_HashableT]: ... |
| 79 |
def pstdev(data: Iterable[_NumberT], mu: _NumberT | None = None) -> _NumberT: ... |
| 80 |
def pvariance(data: Iterable[_NumberT], mu: _NumberT | None = None) -> _NumberT: ... |
| 81 |
def quantiles( |
| 82 |
data: Iterable[_NumberT], *, n: int = 4, method: Literal["inclusive", "exclusive"] = "exclusive" |
| 83 |
) -> list[_NumberT]: ... |
| 84 |
def stdev(data: Iterable[_NumberT], xbar: _NumberT | None = None) -> _NumberT: ... |
| 85 |
def variance(data: Iterable[_NumberT], xbar: _NumberT | None = None) -> _NumberT: ... |
| 86 |
|
| 87 |
class NormalDist: |
| 88 |
__slots__ = {"_mu": "Arithmetic mean of a normal distribution", "_sigma": "Standard deviation of a normal distribution"} |
| 89 |
def __init__(self, mu: float = 0.0, sigma: float = 1.0) -> None: ... |
| 90 |
@property |
| 91 |
def mean(self) -> float: ... |
| 92 |
@property |
| 93 |
def median(self) -> float: ... |
| 94 |
@property |
| 95 |
def mode(self) -> float: ... |
| 96 |
@property |
| 97 |
def stdev(self) -> float: ... |
| 98 |
@property |
| 99 |
def variance(self) -> float: ... |
| 100 |
@classmethod |
| 101 |
def from_samples(cls, data: Iterable[SupportsFloat]) -> Self: ... |
| 102 |
def samples(self, n: SupportsIndex, *, seed: _Seed | None = None) -> list[float]: ... |
| 103 |
def pdf(self, x: float) -> float: ... |
| 104 |
def cdf(self, x: float) -> float: ... |
| 105 |
def inv_cdf(self, p: float) -> float: ... |
| 106 |
def overlap(self, other: NormalDist) -> float: ... |
| 107 |
def quantiles(self, n: int = 4) -> list[float]: ... |
| 108 |
def zscore(self, x: float) -> float: ... |
| 109 |
def __eq__(x1, x2: object) -> bool: ... |
| 110 |
def __add__(x1, x2: float | NormalDist) -> NormalDist: ... |
| 111 |
def __sub__(x1, x2: float | NormalDist) -> NormalDist: ... |
| 112 |
def __mul__(x1, x2: float) -> NormalDist: ... |
| 113 |
def __truediv__(x1, x2: float) -> NormalDist: ... |
| 114 |
def __pos__(x1) -> NormalDist: ... |
| 115 |
def __neg__(x1) -> NormalDist: ... |
| 116 |
__radd__ = __add__ |
| 117 |
def __rsub__(x1, x2: float | NormalDist) -> NormalDist: ... |
| 118 |
__rmul__ = __mul__ |
| 119 |
def __hash__(self) -> int: ... |
| 120 |
|
| 121 |
if sys.version_info >= (3, 12): |
| 122 |
def correlation( |
| 123 |
x: Sequence[_Number], y: Sequence[_Number], /, *, method: Literal["linear", "ranked"] = "linear" |
| 124 |
) -> float: ... |
| 125 |
|
| 126 |
elif sys.version_info >= (3, 10): |
| 127 |
def correlation(x: Sequence[_Number], y: Sequence[_Number], /) -> float: ... |
| 128 |
|
| 129 |
if sys.version_info >= (3, 10): |
| 130 |
def covariance(x: Sequence[_Number], y: Sequence[_Number], /) -> float: ... |
| 131 |
|
| 132 |
class LinearRegression(NamedTuple): |
| 133 |
slope: float |
| 134 |
intercept: float |
| 135 |
|
| 136 |
if sys.version_info >= (3, 11): |
| 137 |
def linear_regression( |
| 138 |
regressor: _SizedIterable[_Number], dependent_variable: _SizedIterable[_Number], /, *, proportional: bool = False |
| 139 |
) -> LinearRegression: ... |
| 140 |
|
| 141 |
elif sys.version_info >= (3, 10): |
| 142 |
def linear_regression( |
| 143 |
regressor: _SizedIterable[_Number], dependent_variable: _SizedIterable[_Number], / |
| 144 |
) -> LinearRegression: ... |
| 145 |
|
| 146 |
if sys.version_info >= (3, 13): |
| 147 |
_Kernel: TypeAlias = Literal[ |
| 148 |
"normal", |
| 149 |
"gauss", |
| 150 |
"logistic", |
| 151 |
"sigmoid", |
| 152 |
"rectangular", |
| 153 |
"uniform", |
| 154 |
"triangular", |
| 155 |
"parabolic", |
| 156 |
"epanechnikov", |
| 157 |
"quartic", |
| 158 |
"biweight", |
| 159 |
"triweight", |
| 160 |
"cosine", |
| 161 |
] |
| 162 |
def kde( |
| 163 |
data: Sequence[float], h: float, kernel: _Kernel = "normal", *, cumulative: bool = False |
| 164 |
) -> Callable[[float], float]: ... |
| 165 |
def kde_random( |
| 166 |
data: Sequence[float], h: float, kernel: _Kernel = "normal", *, seed: _Seed | None = None |
| 167 |
) -> Callable[[], float]: ... |