grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026ó ©&¾4ý…jùã óì•%Sr/SQrSSKrSSKrSSKrSSKrSSKJr SSKJ r SSK J r J r J r SSKJrJr SSKJrJrJrJrJrJrJrJrJr SS KJrJrJrJrJrJrJ r J!r!J"r"J#r# SS K$J%r% SS K&J'r' SS K(J)r)J*r*J+r+ \"S 5r,\r-"SS\.5r/Sr0SbSjr1Sr2Sr3Sr4Sr5ScSjr6SSSSS.S\7\84Sjjr9S\:S\:S\:4Sjr;S \RxRz-S!-r>\:\?S"'S\:S\:S\84S#jr@S\:S\:S\ 4S$jrAS%rBSbS&jrCS'rDSbS(jrES)rFS*rGS+rHSdS,jrIS-rJS.rKSeSS0.S1jjrLS2S3S4.S5jrMSbS6jrNSbS7jrOSbS8jrPSbS9jrQS:rRS;\8S<\8S\84S=jrSS>rTS?S@.SAjrU\*"SBSC5rVSSD.SEjrWSFrXSSGKYJXrX "SHSI5r[SfSJjr\SKr]\\"\]SLSMSN9r^SOr_\\"\_SPSQSN9r`\["5RÂSRSSSTSU\^\`SVSWSX. rb\bS/\bSY'\bSZ\bS['\bS\\bS]'\bS^\bS_'SeSS`.Sajjrcg!\Za N|f=f)ga× Basic statistics module. This module provides functions for calculating statistics of data, including averages, variance, and standard deviation. Calculating averages -------------------- ================== ================================================== Function Description ================== ================================================== mean Arithmetic mean (average) of data. fmean Fast, floating-point arithmetic mean. geometric_mean Geometric mean of data. harmonic_mean Harmonic mean of data. median Median (middle value) of data. median_low Low median of data. median_high High median of data. median_grouped Median, or 50th percentile, of grouped data. mode Mode (most common value) of data. multimode List of modes (most common values of data). quantiles Divide data into intervals with equal probability. ================== ================================================== Calculate the arithmetic mean ("the average") of data: >>> mean([-1.0, 2.5, 3.25, 5.75]) 2.625 Calculate the standard median of discrete data: >>> median([2, 3, 4, 5]) 3.5 Calculate the median, or 50th percentile, of data grouped into class intervals centred on the data values provided. E.g. if your data points are rounded to the nearest whole number: >>> median_grouped([2, 2, 3, 3, 3, 4]) #doctest: +ELLIPSIS 2.8333333333... This should be interpreted in this way: you have two data points in the class interval 1.5-2.5, three data points in the class interval 2.5-3.5, and one in the class interval 3.5-4.5. The median of these data points is 2.8333... Calculating variability or spread --------------------------------- ================== ============================================= Function Description ================== ============================================= pvariance Population variance of data. variance Sample variance of data. pstdev Population standard deviation of data. stdev Sample standard deviation of data. ================== ============================================= Calculate the standard deviation of sample data: >>> stdev([2.5, 3.25, 5.5, 11.25, 11.75]) #doctest: +ELLIPSIS 4.38961843444... If you have previously calculated the mean, you can pass it as the optional second argument to the four "spread" functions to avoid recalculating it: >>> data = [1, 2, 2, 4, 4, 4, 5, 6] >>> mu = mean(data) >>> pvariance(data, mu) 2.5 Statistics for relations between two inputs ------------------------------------------- ================== ==================================================== Function Description ================== ==================================================== covariance Sample covariance for two variables. correlation Pearson's correlation coefficient for two variables. linear_regression Intercept and slope for simple linear regression. ================== ==================================================== Calculate covariance, Pearson's correlation, and simple linear regression for two inputs: >>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> y = [1, 2, 3, 1, 2, 3, 1, 2, 3] >>> covariance(x, y) 0.75 >>> correlation(x, y) #doctest: +ELLIPSIS 0.31622776601... >>> linear_regression(x, y) #doctest: LinearRegression(slope=0.1, intercept=1.5) Exceptions ---------- A single exception is defined: StatisticsError is a subclass of ValueError. )Ú NormalDistÚStatisticsErrorÚ correlationÚ covarianceÚfmeanÚgeometric_meanÚ harmonic_meanÚkdeÚ kde_randomÚlinear_regressionÚmeanÚmedianÚmedian_groupedÚ median_highÚ median_lowÚmodeÚ multimodeÚpstdevÚ pvarianceÚ quantilesÚstdevÚvarianceéN©ÚFraction)ÚDecimal)ÚcountÚgroupbyÚrepeat)Ú bisect_leftÚ bisect_right) ÚhypotÚsqrtÚfabsÚexpÚerfÚtauÚlogÚfsumÚsumprod) ÚisfiniteÚisinfÚpiÚcosÚsinÚtanÚcoshÚasinÚatanÚacos)Úreduce)Ú itemgetter)ÚCounterÚ namedtupleÚ defaultdictç@có•\rSrSrSrg)r阩N)Ú__name__Ú __module__Ú __qualname__Ú__firstlineno__Ú__static_attributes__r<óÚ1/opt/alt/python313/lib64/python3.13/statistics.pyrr˜s†ÚrBrcór•Sn[5nURn0nURn[U[5H9upgU"U5 [ [ U5Hup‰US- nU"U S5U-XI'M M; SU;aUSn O [SUR555n [[U[5n XºU4$)aT_sum(data) -> (type, sum, count) Return a high-precision sum of the given numeric data as a fraction, together with the type to be converted to and the count of items. Examples -------- >>> _sum([3, 2.25, 4.5, -0.5, 0.25]) (, Fraction(19, 2), 5) Some sources of round-off error will be avoided: # Built-in sum returns zero. >>> _sum([1e50, 1, -1e50] * 1000) (, Fraction(1000, 1), 3000) Fractions and Decimals are also supported: >>> from fractions import Fraction as F >>> _sum([F(2, 3), F(7, 5), F(1, 4), F(5, 6)]) (, Fraction(63, 20), 4) >>> from decimal import Decimal as D >>> data = [D("0.1375"), D("0.2108"), D("0.3061"), D("0.0419")] >>> _sum(data) (, Fraction(6963, 10000), 4) Mixed types are currently treated as an error, except that int is allowed. réNc3ó<# •UHup[X!5v• M g7f©Nr©Ú.0ÚdÚns rCÚ Ú_sum..Ïsé€Ð@Ò/?¡t q”H˜Q—N�NÒ/?ùó‚) ÚsetÚaddÚgetrÚtypeÚmapÚ _exact_ratioÚsumÚitemsr4Ú_coerceÚint) ÚdatarÚtypesÚ types_addÚpartialsÚ partials_getÚtypÚvaluesrKrJÚtotalÚTs rCÚ_sumrbžs¸€ð@ €EÜ ‹E€EØ— ‘ €IØ€HØ—<‘<€Lܘt¤TÖ*‰ ˆÙ�#ŒÜœ  fÖ-‰DˆAØ �Q‰JˆEÙ& q¨!Ó,¨qÑ0ˆH‹Kó.ñ+ð  ˆxÓ𘑉ôÑ@¨x¯~©~Ô/?Ó@Ó@ˆÜŒw˜œsÓ#€AØ �eÐ ÐrBcó†^^•Tb[UU4SjU55up#nX#TU4$Sn[5nURn[[5n[[5n[ U[ 5HHupšU"U 5 [[U 5H'un mUS- nUT==U - ss'UT==X»-- ss'M) MJ U(d[S5=nmO^SU;aUS=nmOP[SUR555n [SUR555n XM-XÌ-- U- nXÄ- m[[U[5nX#TU4$)a#Return the exact mean and sum of square deviations of sequence data. Calculations are done in a single pass, allowing the input to be an iterator. If given *c* is used the mean; otherwise, it is calculated from the data. Use the *c* argument with care, as it can lead to garbage results. Nc3ó6># •UHoT- =mT-v• M g7frGr<)rIÚxÚcrJs €€rCrLÚ_ss..Þsøé€Ð<²t°! q¡5˜j˜a¨AÖ-²tùsƒrrEc3ó<# •UHup[X!5v• M g7frGrrHs rCrLrgósé€Ð@Ò,?¡D A”˜!—�Ò,?ùrNc3óB# •UHup[X!U-5v• M g7frGrrHs rCrLrgôs é€ÐDÒ/C¡t q”(˜1 ™c×"Ð"Ò/Cùs‚)rbrOrPr8rXrrRrSrTrrUrVr4rW)rYrfraÚssdrrZr[Ú sx_partialsÚ sxx_partialsr^r_rKÚsxÚsxxrJs ` @rCÚ_ssroÔsAù€ð �}ÜÕ<±tÓ<Ó<‰ ˆ�ؘ˜5Ð!Ð!Ø €EÜ ‹E€EØ— ‘ €IÜœcÓ"€KÜœsÓ#€Lܘt¤TÖ*‰ ˆÙ�#ŒÜœ  fÖ-‰DˆAˆqØ �Q‰JˆEØ ˜‹N˜aÑ ‹NØ ˜‹O˜q™uÑ $�Oó.ñ+ö ܘ1“+Ј‰aØ �Ó ð˜dÑ#Ð#ˆ‰aôÑ@¨K×,=Ñ,=Ô,?Ó@Ó @ˆÜÑD¨|×/AÑ/AÔ/CÓDÓDˆð‰{˜R™WÑ$¨Ñ-ˆØ ‰JˆÜŒw˜œsÓ#€AØ �A�uÐ ÐrBcóp•UR5$![a [R"U5s$f=frG)Ú is_finiteÚAttributeErrorÚmathr*)res rCÚ _isfinitertýs1€ð Ø�{‰{‹}ÐøÜ ó Ü�}Š}˜QÓÒð ús ‚’ 5´5cóê•XLaU$U[Ld U[LaU$U[LaU$[X5(aU$[X5(aU$[U[5(aU$[U[5(aU$[U[5(a[U[5(aU$[U[5(a[U[5(aU$Sn[ X R UR 4-5e)z±Coerce types T and S to a common type, or raise TypeError. Coercion rules are currently an implementation detail. See the CoerceTest test class in test_statistics for details. z"don't know how to coerce %s and %s)rXÚboolÚ issubclassrÚfloatÚ TypeErrorr=)raÚSÚmsgs rCrWrWsÅ€ð ‚v�q�àŒC‚x�1œ’9 a˜xØŒC‚x˜�(ä�!×Ñ ˜(Ü�!×Ñ ˜(ä�!”S×Ñ 1˜HÜ�!”S×Ñ 1˜Hä�!”X×Ѥ:¨a´×#7Ñ#7؈Ü�!”U×Ѥ ¨1¬h× 7Ñ 7؈à .€CÜ �CŸ:™: q§z¡zÐ2Ñ2Ó 3Ð3rBcó•UR5$![a O[[4a US4s$f=fURUR 4$![a% S[ U5RS3n[U5ef=f)z•Return Real number x to exact (numerator, denominator) pair. >>> _exact_ratio(0.25) (1, 4) x is expected to be an int, Fraction, Decimal or float. Nzcan't convert type 'z' to numerator/denominator) Úas_integer_ratiorrÚ OverflowErrorÚ ValueErrorÚ numeratorÚ denominatorrRr=ry)rer{s rCrTrT#sŒ€ð<Ø×!Ñ!Ó#Ð#øÜ ó Ù Ü œ:Ð &óð�4ˆyÒðúðà— ‘ ˜QŸ]™]Ð+Ð+øÜ óØ$¤T¨!£W×%5Ñ%5Ð$6Ð6PÐQˆÜ˜‹nÐðús‚’ 4ž4³4¸AÁ/A?có •[U5ULaU$[U[5(aURS:wa[nU"U5$![ a> [U[ 5(a'U"UR5U"UR5- s$ef=f)z&Convert value to given numeric type T.rE)rRrwrXr�rxryrr€)Úvalueras rCÚ_convertr„Qs€€ä ˆEƒ{�aÒðˆ Ü�!”S×јe×/Ñ/°1Ó4Ü ˆðá�‹xˆøÜ óÜ �aœ× !Ñ !Ù�U—_‘_Ó%©¨%×*;Ñ*;Ó(<Ñ<Ò <à ð ús½AÁAB  B c#óH# •UHnUS:a [U5eUv• M g7f)z7Iterate over values, failing if any are less than zero.rN)r)r_Úerrmsgres rCÚ _fail_negr‡cs&é€ã ˆØ ˆq‹5Ü! &Ó)Ð )ØŒòùs‚ "FÚaveragerE)ÚkeyÚreverseÚtiesÚstartÚreturncóJ•US:wa[SU<35eUb [X5n[[U[ 55US9nUS- nS/[ U5-n[ U[S5S9H8up‰[U 5n [ U 5n XkS-S- -n U H upÞXÇU'M Xk- nM: U$)a½Rank order a dataset. The lowest value has rank 1. Ties are averaged so that equal values receive the same rank: >>> data = [31, 56, 31, 25, 75, 18] >>> _rank(data) [3.5, 5.0, 3.5, 2.0, 6.0, 1.0] The operation is idempotent: >>> _rank([3.5, 5.0, 3.5, 2.0, 6.0, 1.0]) [3.5, 5.0, 3.5, 2.0, 6.0, 1.0] It is possible to rank the data in reverse order so that the highest value has rank 1. Also, a key-function can extract the field to be ranked: >>> goals = [('eagles', 45), ('bears', 48), ('lions', 44)] >>> _rank(goals, key=itemgetter(1), reverse=True) [2.0, 1.0, 3.0] Ranks are conventionally numbered starting from one; however, setting *start* to zero allows the ranks to be used as array indices: >>> prize = ['Gold', 'Silver', 'Bronze', 'Certificate'] >>> scores = [8.1, 7.3, 9.4, 8.3] >>> [prize[int(i)] for i in _rank(scores, start=0, reverse=True)] ['Bronze', 'Certificate', 'Gold', 'Silver'] rˆzUnknown tie resolution method: )rŠrEr)r‰é) rrSÚsortedÚziprÚlenrr5Úlist)rYr‰rŠr‹rŒÚval_posÚiÚresultÚ_ÚgÚgroupÚsizeÚrankrƒÚorig_poss rCÚ_rankr�ks·€ðJ ˆyÓÜÐ:¸4¹(ÐCÓDÐDØ �Ü�3‹~ˆÜ”S˜œu›wÓ'°Ñ9€GØ �‰ €A؈S”3�w“<Ñ €Fܘ¤Z°£]Ô3‰ˆÜ�Q“ˆÜ�5‹zˆØ˜1‘H ‘>Ñ!ˆÛ$‰OˆEØ#�8Ó ñ %à ‰ Šñ 4ð €MrBrKÚmcóL•[R"X-5nX"U-U-U:g-$)zFSquare root of n/m, rounded to the nearest integer using round-to-odd.)rsÚisqrt)rKržÚas rCÚ_integer_sqrt_of_frac_rtor¢¡s)€ô � Š �1‘6Ó€AØ �!‘�A‘˜‘ Ñ ÐrBr�éÚ_sqrt_bit_widthcóЕUR5UR5- [- S-nUS:¼a[XSU--5U-nSnX4- $[USU--U5nSU*-nX4- $)z1Square root of n/m as a float, correctly rounded.r�rrEéþÿÿÿ)Ú bit_lengthr¤r¢)rKržÚqr€r�s rCÚ_float_sqrt_of_fracr©­s|€ð �‰‹˜!Ÿ,™,›.Ñ (¬?Ñ :¸qÑ@€A؈AƒvÜ-¨a°a¸!±e±Ó<ÀÑAˆ ؈ ð Ñ "Ð"ô.¨a°2¸±6©k¸1Ó=ˆ ؘA˜2‘gˆ Ø Ñ "Ð"rBcó¶•US::aU(d [S5$U*U*p[U5[U5- R5nUR5up4UR5nUR5upgSU-XG-S--XU-Xs--S--:”aU$UR 5nUR5upšSU-XJ-S--XU -X£--S--:aU$U$)z3Square root of n/m as a Decimal, correctly rounded.rz0.0ér�)rr"r}Ú next_plusÚ next_minus) rKržÚrootÚnrÚdrÚplusÚnpÚdpÚminusÚnmÚdms rCÚ_decimal_sqrt_of_fracr·ºsç€ð  ˆAƒvÞܘ5“>Ð !؈r�A�2ˆ1ä �A‹Jœ ›Ñ #× )Ñ )Ó +€DØ × "Ñ "Ó $�F€Bà �>‰>Ó €DØ × "Ñ "Ó $�F€Bàˆ1�u�‘˜‰zјA B¡¨©¡°Ñ 2Ñ2Ó2؈ à �O‰OÓ €EØ × #Ñ #Ó %�F€Bàˆ1�u�‘˜‰zјA B¡¨©¡°Ñ 2Ñ2Ó2؈ à €KrBcó\•[U5upnUS:a [S5e[X#- U5$)a[Return the sample arithmetic mean of data. >>> mean([1, 2, 3, 4, 4]) 2.8 >>> from fractions import Fraction as F >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)]) Fraction(13, 21) >>> from decimal import Decimal as D >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")]) Decimal('0.5625') If ``data`` is empty, StatisticsError will be raised. rEz%mean requires at least one data point)rbrr„)rYrar`rKs rCr r Øs3€ô �t“*�K€Aˆa؈1ƒuÜÐEÓFÐFÜ �E‘I˜qÓ !Ð!rBcó~^•Uc.[U5m[U5nT(d [S5eUT- $[ U[ [ 45(d [ U5n[X5n[U5nU(d [S5eXE- $![a SmU4SjnU"U5nN‘f=f![a [S5ef=f)zàConvert data to floats and compute the arithmetic mean. This runs faster than the mean() function and it always returns a float. If the input dataset is empty, it raises a StatisticsError. >>> fmean([3.5, 4.0, 5.25]) 4.25 rc3ó>># •[USS9H umnUv• M g7f)NrE©rŒ)Ú enumerate)ÚiterablererKs €rCrÚfmean..countýs øé€ä% h°aÔ8‘D�A�qØ”Gò9ùsƒz&fmean requires at least one data pointz(data and weights must be the same lengthzsum of weights must be non-zero) r’ryr(rÚ isinstancer“Útupler)r)rYÚweightsrr`ÚnumÚdenrKs @rCrrîsÌø€ð�ð Ü�D“ ˆAô�T“ ˆÞÜ!Ð"JÓKÐ KØ�q‰yÐÜ �g¤¤e˜}× -Ñ -Ü�w“-ˆðJÜ�dÓ$ˆô ˆw‹-€CÞ ÜÐ?Ó@Ð@Ø ‰9Ðøô+ó àˆAõ ñ˜“;ŠDð ûô óJÜÐHÓIÐIðJús† BÁ B&ÂB#Â"B#Â&B<cóJ^^•SmSmUU4Sjn[[[U"U555nT(d [S5e[R "U5(a[R $T(a&U[R:Xa[R $S$[UT- 5$)aUConvert data to floats and compute the geometric mean. Raises a StatisticsError if the input dataset is empty or if it contains a negative value. Returns zero if the product of inputs is zero. No special efforts are made to achieve exact results. (However, this may change in the future.) >>> round(geometric_mean([54, 24, 36]), 9) 36.0 rFc3ó¬># •[USS9HAumnUS:”d[R"U5(aUv• M-US:XaSmM7[SU5e g7f)NrEr»çTzNo negative inputs allowed)r¼rsÚisnanr)r½reÚ found_zerorKs €€rCÚcount_positiveÚ&geometric_mean..count_positive"sMøé€ä˜h¨aÔ0‰DˆAˆqØ�3‹wœ$Ÿ*š* QŸ-™-Ø”Ø�c“Ø!’ ä%Ð&BÀAÓFÐFò 1ùsƒAAzMust have a non-empty datasetrÆ) r(rSr'rrsrÇÚnanÚinfr$)rYrÉr`rÈrKs @@rCrrsù€ð €AØ€JöGô ””S™.¨Ó.Ó/Ó 0€EÞ ÜÐ=Ó>Ð>Ü ‡z‚z�%×ÑÜ�x‰xˆÞØ ¤D§H¡HÓ,Œt�x‰xÐ5°#Ð5Ü ˆu�q‰y‹>ÐrBcóŠ•[U5ULa [U5nSn[U5nUS:a [S5eUS:XaKUcHUSn[ U[ R [45(aUS:a [U5eU$[S5eUc[SU5nUnOQ[U5ULa [U5n[U5U:wa [S5e[S[X555upen[X5n[S[X555upxn US::a [S 5e[XX- U5$![a gf=f) a¢Return the harmonic mean of data. The harmonic mean is the reciprocal of the arithmetic mean of the reciprocals of the data. It can be used for averaging ratios or rates, for example speeds. Suppose a car travels 40 km/hr for 5 km and then speeds-up to 60 km/hr for another 5 km. What is the average speed? >>> harmonic_mean([40, 60]) 48.0 Suppose a car travels 40 km/hr for 5 km, and when traffic clears, speeds-up to 60 km/hr for the remaining 30 km of the journey. What is the average speed? >>> harmonic_mean([40, 60], weights=[5, 30]) 56.0 If ``data`` is empty, or any element is less than zero, ``harmonic_mean`` will raise ``StatisticsError``. z.harmonic mean does not support negative valuesrEz.harmonic_mean requires at least one data pointrzunsupported typez*Number of weights does not match data sizec3ó$# •UHov• M g7frGr<)rIÚws rCrLÚ harmonic_mean..bsé€Ð GÒ,F q¤Ò,Fùs‚c3ó@# •UHupU(aX- OSv• M g7f)rNr<)rIrÏres rCrLrÐesé€ÐPÒ=O±T°Q®˜qšu¨qÔ0Ò=Oùs‚zWeighted sum must be positive)Úiterr“r’rr¿ÚnumbersÚRealrryrrbr‡r‘ÚZeroDivisionErrorr„) rYrÁr†rKreÚ sum_weightsr—rar`rs rCrr5sD€ô. ˆDƒz�TÒÜ�D‹zˆØ =€FÜ ˆD‹ €A؈1ƒuÜÐNÓOÐOØ ˆa‹�G‘OØ �‰GˆÜ �aœ'Ÿ,™,¬Ð0× 1Ñ 1Ø�1‹uÜ% fÓ-Ð-؈HäÐ.Ó/Ð /Ø�ܘ˜A“,ˆØ‰ ä �‹=˜GÒ #ܘ7“mˆGÜ ˆw‹<˜1Ó Ü!Ð"NÓOÐ OÜ Ñ G¬I°gÔ,FÓ GÓGш˜ðܘÓ&ˆÜÑP¼SÀÔ=OÓPÓP‰ˆ�%ð �ƒzÜÐ=Ó>Ð>Ü �KÑ'¨Ó +Ð+øô óÙðúsÃ-)D5Ä5 EÅEcó˜•[U5n[U5nUS:Xa [S5eUS-S:XaXS-$US-nXS- X-S- $)a"Return the median (middle value) of numeric data. When the number of data points is odd, return the middle data point. When the number of data points is even, the median is interpolated by taking the average of the two middle values: >>> median([1, 3, 5]) 3 >>> median([1, 3, 5, 7]) 4.0 rúno median for empty datar�rE©r�r’r)rYrKr•s rCr r msa€ô �$‹<€DÜ ˆD‹ €A؈AƒvÜÐ8Ó9Ð9؈1�u�ƒzؘ‘F‰|Ðà �‰FˆØ˜‘U‘ ˜d™gÑ%¨Ñ*Ð*rBcó„•[U5n[U5nUS:Xa [S5eUS-S:XaXS-$XS-S- $)zíReturn the low median of numeric data. When the number of data points is odd, the middle value is returned. When it is even, the smaller of the two middle values is returned. >>> median_low([1, 3, 5]) 3 >>> median_low([1, 3, 5, 7]) 3 rrØr�rErÙ©rYrKs rCrr…sQ€ô �$‹<€DÜ ˆD‹ €A؈AƒvÜÐ8Ó9Ð9؈1�u�ƒzؘ‘F‰|Ðà˜‘F˜Q‘JÑÐrBcó^•[U5n[U5nUS:Xa [S5eXS-$)zçReturn the high median of data. When the number of data points is odd, the middle value is returned. When it is even, the larger of the two middle values is returned. >>> median_high([1, 3, 5]) 3 >>> median_high([1, 3, 5, 7]) 5 rrØr�rÙrÛs rCrr›s5€ô �$‹<€DÜ ˆD‹ €A؈AƒvÜÐ8Ó9Ð9Ø �Q‘‰<ÐrBcó$•[U5n[U5nU(d [S5eXS-n[X5n[ XUS9n[ U5n[ U5nX1S- - nUnXT- nXaUS- U- -U- -$![ a [S5ef=f)aEstimates the median for numeric data binned around the midpoints of consecutive, fixed-width intervals. The *data* can be any iterable of numeric data with each value being exactly the midpoint of a bin. At least one value must be present. The *interval* is width of each bin. For example, demographic information may have been summarized into consecutive ten-year age groups with each group being represented by the 5-year midpoints of the intervals: >>> demographics = Counter({ ... 25: 172, # 20 to 30 years old ... 35: 484, # 30 to 40 years old ... 45: 387, # 40 to 50 years old ... 55: 22, # 50 to 60 years old ... 65: 6, # 60 to 70 years old ... }) The 50th percentile (median) is the 536th person out of the 1071 member cohort. That person is in the 30 to 40 year old age group. The regular median() function would assume that everyone in the tricenarian age group was exactly 35 years old. A more tenable assumption is that the 484 members of that age group are evenly distributed between 30 and 40. For that, we use median_grouped(). >>> data = list(demographics.elements()) >>> median(data) 35 >>> round(median_grouped(data, interval=10), 1) 37.5 The caller is responsible for making sure the data points are separated by exact multiples of *interval*. This is essential for getting a correct result. The function does not check this precondition. Inputs may be any numeric type that can be coerced to a float during the interpolation step. rØr�)Úloz$Value cannot be converted to a floatr9)r�r’rrr rxrry) rYÚintervalrKrer•ÚjÚLÚcfÚfs rCrr®s·€ôV �$‹<€DÜ ˆD‹ €AÞ ÜÐ8Ó9Ð9ð �!‰V‰ €Aô �DÓ€AÜ�T Ñ#€AðAܘ“?ˆÜ �!‹Hˆð �s‰NÑ€AØ €BØ ‰€AØ ˜1˜q™5 2™:Ñ&¨Ñ*Ñ *Ð*øô óAÜÐ>Ó@Ð@ðAús ÁA9Á9BcóŽ•[[U55RS5nUSS$![a [ S5Sef=f)aDReturn the most common data point from discrete or nominal data. ``mode`` assumes discrete data, and returns a single value. This is the standard treatment of the mode as commonly taught in schools: >>> mode([1, 1, 2, 3, 3, 3, 3, 4]) 3 This also works with nominal (non-numeric) data: >>> mode(["red", "blue", "blue", "red", "green", "red", "red"]) 'red' If there are multiple modes with same frequency, return the first one encountered: >>> mode(['red', 'red', 'green', 'blue', 'blue']) 'red' If *data* is empty, ``mode``, raises StatisticsError. rErzno mode for empty dataN)r6rÒÚ most_commonÚ IndexErrorr)rYÚpairss rCrrösP€ô. ”D˜“JÓ × +Ñ +¨AÓ .€EðBØ�Q‰x˜‰{ÐøÜ óBÜÐ6Ó7¸TÐAðBús ¥-­AcóÒ•[[U55nU(d/$[UR55nUR 5VVs/sHup4XB:XdM UPM snn$s snnf)a Return a list of the most frequently occurring values. Will return more than one result if there are multiple modes or an empty list if *data* is empty. >>> multimode('aabbbbbbbbcc') ['b'] >>> multimode('aabbbbccddddeeffffgg') ['b', 'd', 'f'] >>> multimode('') [] )r6rÒÚmaxr_rV)rYÚcountsÚmaxcountrƒrs rCrrsO€ô”T˜$“ZÓ €FÞ Øˆ Ü�6—=‘=“?Ó#€HØ&,§l¡l¤nÔ J¢n‘l�e¸Ñ8I�E¡nÒ JÐJùÓ Js Á A#ÁA#Únormal)Ú cumulativecóÚ^^^^^ ^ ^ ^ ^ ^^•[T5m T (d [S5e[TS[[45(d [ S5eTS::a[ST<35eU==S:XaO =S:XaO O. [ S[-5m[ S5mU4S jmU4S jmS nOã=S :Xa S mSmS nOÓ=S:Xa" S[- m S[- m U 4SjmU 4SjmS nO«==S:XaO =S:XaO O SmSmSnO�=S:Xa SmSmSnO==S:XaO =S:XaO O SmSmSnOc==S:XaO =S :XaO O S!mS"mSnOG=S#:Xa S$mS%mSnO7S&:Xa"[S'- m [S- m U U 4S(jmU 4S)jmSnO[S*U<35eUcUUU4S+jnUUU4S,jnO&[T5m TU-m UU UUU U 4S-jnUU UUU U 4S.jnU(aS/T<S0U<3Ul U$S1T<S0U<3Ul U$)2aÿ Kernel Density Estimation: Create a continuous probability density function or cumulative distribution function from discrete samples. The basic idea is to smooth the data using a kernel function to help draw inferences about a population from a sample. The degree of smoothing is controlled by the scaling parameter h which is called the bandwidth. Smaller values emphasize local features while larger values give smoother results. The kernel determines the relative weights of the sample data points. Generally, the choice of kernel shape does not matter as much as the more influential bandwidth smoothing parameter. Kernels that give some weight to every sample point: normal (gauss) logistic sigmoid Kernels that only give weight to sample points within the bandwidth: rectangular (uniform) triangular parabolic (epanechnikov) quartic (biweight) triweight cosine If *cumulative* is true, will return a cumulative distribution function. A StatisticsError will be raised if the data sequence is empty. Example ------- Given a sample of six data points, construct a continuous function that estimates the underlying probability density: >>> sample = [-2.1, -1.3, -0.4, 1.9, 5.1, 6.2] >>> f_hat = kde(sample, h=1.5) Compute the area under the curve: >>> area = sum(f_hat(x) for x in range(-20, 20)) >>> round(area, 4) 1.0 Plot the estimated probability density function at evenly spaced points from -6 to 10: >>> for x in range(-6, 11): ... density = f_hat(x) ... plot = ' ' * int(density * 400) + 'x' ... print(f'{x:2}: {density:.3f} {plot}') ... -6: 0.002 x -5: 0.009 x -4: 0.031 x -3: 0.070 x -2: 0.111 x -1: 0.125 x 0: 0.110 x 1: 0.086 x 2: 0.068 x 3: 0.059 x 4: 0.066 x 5: 0.082 x 6: 0.082 x 7: 0.058 x 8: 0.028 x 9: 0.009 x 10: 0.002 x Estimate P(4.5 < X <= 7.5), the probability that a new sample value will be between 4.5 and 7.5: >>> cdf = kde(sample, h=1.5, cumulative=True) >>> round(cdf(7.5) - cdf(4.5), 2) 0.22 References ---------- Kernel density estimation and its application: https://www.itm-conferences.org/articles/itmconf/pdf/2018/08/itmconf_sam2018_00037.pdf Kernel functions in common use: https://en.wikipedia.org/wiki/Kernel_(statistics)#kernel_functions_in_common_use Interactive graphical demonstration and exploration: https://demonstrations.wolfram.com/KernelDensityEstimation/ Kernel estimation of cumulative distribution function of a random variable with bounded support https://www.econstor.eu/bitstream/10419/207829/1/10.21307_stattrans-2016-037.pdf úEmpty data sequencerú)Data sequence must contain ints or floatsrÆú$Bandwidth h must be positive, not h=rìÚgaussr�có,>•[SU-U-5T- $)Nçà¿©r$)ÚtÚsqrt2pis €rCÚÚkde..›sø€œ#˜d Q™h¨™lÓ+¨gÒ5rBcó,>•SS[UT- 5--$©Nçà?çð?)r%)röÚsqrt2s €rCrørùœsø€˜# ¤s¨1¨u©9£~Ñ!5Ò6rBNÚlogisticcó$•SS[U5-- $rû©r0©rös rCrørù¡s€˜# ¤t¨A£w¡Ò/rBcó*•SS[U5S-- - $©Nrýrõrs rCrørù¢s€˜# ¤s¨1£v°¡|Ñ 4Ò4rBÚsigmoidrEcó >•T[U5- $rGr)röÚc1s €rCrørù©s ø€˜"œt A›wš,rBcó2>•T[[U55-$rG)r2r$©röÚc2s €rCrørùªsø€˜"œt¤C¨£F›|Ò+rBÚ rectangularÚuniformcó•g©Nrür<rs rCrørù®s€˜#rBcó•SU-S-$rr<rs rCrørù¯s €˜# ™' Cš-rBrýÚ triangularcó•S[U5- $r©Úabsrs rCrørù³s €˜#¤ A£š,rBcó,•X-US:aSOS-U-S-$)NrÆrürôr<rs rCrørù´s€˜!™#¨¨C«¡°TÑ:¸QÑ>ÀÒDrBÚ parabolicÚ epanechnikovcó•SSX-- -$)Nçè?rýr<rs rCrørù¸s€˜#  q¡u¡Ò-rBcó$•SUS--SU--S-$)Ngпr£rrür<rs rCrørù¹s€˜$  A¡™+¨¨a©Ñ/°#Ò5rBÚquarticÚbiweightcó•SSX-- S--$©Nçî?rýr�r<rs rCrørù½ó€˜% 3¨©¡;°1Ñ"4Ò4rBcó6•SUS--SUS--- SU--S-$©NgÈ?égä?r£rrür<rs rCrørù¾s'€˜$  A¡™+¨¨a°©d© Ñ2°U¸Q±YÑ>ÀÒDrBÚ triweightcó•SSX-- S--$©Nç€ñ?rýr£r<rs rCrørùÂrrBcóB•SSUS--SUS---US-- U--S-$©Nr&g’$I’$I¿ég333333ã?r"r£rür<rs rCrørùÃs1€˜% 4¨¨1©¡9¨s°1°a±4©xÑ#7¸!¸Q¹$Ñ#>ÀÑ#BÑCÀcÒIrBÚcosiner«có&>•T[TU-5-$rG)r-)rörr s €€rCrørùÉsø€˜"œs 2¨¡6›{Ò*rBcó,>•S[TU-5-S-$r©r.r s €rCrørùÊsø€˜#¤ B¨¡F£ Ñ+¨cÒ1rBúUnknown kernel name: cóV>^•[T5n[UUU4SjT55UT-- $)Nc3ó@># •UHnT"TU- T- 5v• M g7frGr<©rIÚx_iÚKÚhres €€€rCrLÚ#kde..pdf..Ôó!øé€Ð8²4¨C‘q˜!˜c™' Q™×'Ð'²4ùóƒ©r’rU)rerKr3rYr4s` €€€rCÚpdfÚkde..pdfÒs&ù€Ü�D“ ˆAÜÖ8±4Ó8Ó8¸AÀ¹EÑBÐ BrBcóP>^•[T5n[UUU4SjT55U- $)Nc3ó@># •UHnT"TU- T- 5v• M g7frGr<©rIr2ÚWr4res €€€rCrLÚ#kde..cdf..Ør6r7r8)rerKr>rYr4s` €€€rCÚcdfÚkde..cdfÖs"ù€Ü�D“ ˆAÜÖ8±4Ó8Ó8¸1Ñ<Ð ^•[T5T:wa[T5m [T5m[T TT- 5n[T TT-5nT Xn[ UUU4SjU55TT-- $)Nc3ó@># •UHnT"TU- T- 5v• M g7frGr<r1s €€€rCrLr5çs!øé€Ð=²9¨C‘q˜!˜c™' Q™×'Ð'²9ùr7©r’r�rr rU) rer•ràÚ supportedr3Ú bandwidthrYr4rKÚsamples ` €€€€€€rCr9r:ßscù€ä�4‹y˜A‹~Ü ›�ܘ“I�ܘF A¨ ¡MÓ2ˆAܘV Q¨¡]Ó3ˆAؘq˜ ˆIÜÖ=±9Ó=Ó=ÀÀQÁÑGÐ GrBcóÊ>^•[T5T:wa[T5m [T5m[T TT- 5n[T TT-5nT Xn[ UUU4SjU5U5T- $)Nc3ó@># •UHnT"TU- T- 5v• M g7frGr<r=s €€€rCrLr?ñs!øé€Ð>²I¨S™˜1˜s™7 a™-×(Ð(²Iùr7rD) rer•ràrEr>rFrYr4rKrGs ` €€€€€€rCr@rAésaù€ä�4‹y˜A‹~Ü ›�ܘ“I�ܘF A¨ ¡MÓ2ˆAܘV Q¨¡]Ó3ˆAؘq˜ ˆIÜÖ>±IÓ>ÀÓBÀQÑFÐ FrBzCDF estimate with h=ú and kernel=zPDF estimate with h=) r’rr¿rXrxryr"r,r�Ú__doc__)rYr4ÚkernelríÚsupportr9r@r3r>rFrr rKrGrþr÷s`` @@@@@@@@@rCr r (såÿú€ôH ˆD‹ €AÞ ÜÐ3Ó4Ð4ä �d˜1‘g¤¤U˜|× ,Ñ ,ÜÐCÓDÐDàˆCƒxÜÐ EÀ1Á&ÐIÓJÐJà à ŽXžÓ ܘ1œr™6“lˆGܘ“GˆEÜ5ˆAÜ6ˆA؉Gæ á/ˆAÙ4ˆA؉Gæ à”R‘ˆBØ”R‘ˆBÜ&ˆAÜ+ˆA؉Gà &Ž]žYÓ &ÙˆAÙ'ˆA؉Gæ Ù&ˆAÙDˆA؉Gà )Ž[ž>Ó )Ù-ˆAÙ5ˆA؉Gà #ŽYžÓ #Ù4ˆAÙDˆA؉Gæ Ù4ˆAÙIˆA؉Gä Ü�a‘ˆBÜ�a‘ˆBÝ*ˆAÜ1ˆA؉Gà Ü!Ð$9¸&¹Ð"DÓEÐ Eà�÷ C÷ =ð =ô ˜“ˆØ˜‘Kˆ ÷ Hò H÷ Gò GöØ-¨1©&° °f±[ÐAˆŒ ؈ ð.¨1©&° °f±[ÐAˆŒ ؈ rBr«Ú exclusive)rKÚmethodcó@•US:a [S5e[U5n[U5nUS:aUS:XaXS- -$[S5eUS:XaTUS- n/n[SU5H;n[ Xd-U5upxXX- -XS-U--U- n UR U 5 M= U$US:XakUS-n/n[SU5HRnXd-U-nUS:aSOXsS- :”aUS- OUnXd-Xq-- nXS- X- -XU--U- n UR U 5 MT U$[ SU<35e)aeDivide *data* into *n* continuous intervals with equal probability. Returns a list of (n - 1) cut points separating the intervals. Set *n* to 4 for quartiles (the default). Set *n* to 10 for deciles. Set *n* to 100 for percentiles which gives the 99 cuts points that separate *data* in to 100 equal sized groups. The *data* can be any iterable containing sample. The cut points are linearly interpolated between data points. If *method* is set to *inclusive*, *data* is treated as population data. The minimum value is treated as the 0th percentile and the maximum value is treated as the 100th percentile. rEzn must be at least 1r�z!must have at least one data pointÚ inclusiverNúUnknown method: )rr�r’ÚrangeÚdivmodÚappendr) rYrKrOÚldržr–r•ràÚdeltaÚ interpolateds rCrr!s\€ð  ˆ1ƒuÜÐ4Ó5Ð5Ü �$‹<€DÜ ˆT‹€BØ ˆAƒvØ �‹7ؘq™5‘>Ð !ÜÐAÓBÐBà �ÓØ �‰FˆØˆÜ�q˜!–ˆAܘa™e QÓ'‰HˆAØ ™G q¡yÑ1°D¸Q¹±KÀ%Ñ4GÑGÈ1ÑLˆLØ �M‰M˜,Ö 'ñðˆ à �ÓØ �‰FˆØˆÜ�q˜!–ˆAØ‘˜‘ ˆAؘ“U‘¨¨q©D«  1¢°aˆAØ‘C˜!™#‘IˆEØ  Q¡™K¨1©9Ñ5¸¹À%¹ÑGÈ1ÑLˆLØ �M‰M˜,Ö 'ñ ð ˆ ä Ð'¨¡zÐ2Ó 3Ð3rBcób•[X5up#pEUS:a [S5e[X5S- - U5$)a^Return the sample variance of data. data should be an iterable of Real-valued numbers, with at least two values. The optional argument xbar, if given, should be the mean of the data. If it is missing or None, the mean is automatically calculated. Use this function when your data is a sample from a population. To calculate the variance from the entire population, see ``pvariance``. Examples: >>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5] >>> variance(data) 1.3720238095238095 If you have already calculated the mean of your data, you can pass it as the optional second argument ``xbar`` to avoid recalculating it: >>> m = mean(data) >>> variance(data, m) 1.3720238095238095 This function does not check that ``xbar`` is actually the mean of ``data``. Giving arbitrary values for ``xbar`` may lead to invalid or impossible results. Decimals and Fractions are supported: >>> from decimal import Decimal as D >>> variance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")]) Decimal('31.01875') >>> from fractions import Fraction as F >>> variance([F(1, 6), F(1, 2), F(5, 3)]) Fraction(67, 108) r�z*variance requires at least two data pointsrE©rorr„)rYÚxbarraÚssrfrKs rCrrWs8€ôL�d“/�K€Aˆ1؈1ƒuÜÐJÓKÐKÜ �B˜a™%‘L !Ó $Ð$rBcó\•[X5up#pEUS:a [S5e[X5- U5$)aÐReturn the population variance of ``data``. data should be a sequence or iterable of Real-valued numbers, with at least one value. The optional argument mu, if given, should be the mean of the data. If it is missing or None, the mean is automatically calculated. Use this function to calculate the variance from the entire population. To estimate the variance from a sample, the ``variance`` function is usually a better choice. Examples: >>> data = [0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25] >>> pvariance(data) 1.25 If you have already calculated the mean of the data, you can pass it as the optional second argument to avoid recalculating it: >>> mu = mean(data) >>> pvariance(data, mu) 1.25 Decimals and Fractions are supported: >>> from decimal import Decimal as D >>> pvariance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")]) Decimal('24.815') >>> from fractions import Fraction as F >>> pvariance([F(1, 4), F(5, 4), F(1, 2)]) Fraction(13, 72) rEz*pvariance requires at least one data pointrZ)rYÚmurar\rfrKs rCrrƒs4€ôF�d“-�K€Aˆ1؈1ƒuÜÐJÓKÐKÜ �B‘F˜AÓ ÐrBcó•[X5up#pEUS:a [S5eX5S- - nURnURn[ U[5(a [Xx5$[Xx5$![a [ S5ef=f)z¤Return the square root of the sample variance. See ``variance`` for arguments and other details. >>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) 1.0810874155219827 r�ú'stdev requires at least two data pointsrEúinf or nan encountered in data© rorr€r�rrrrwrr·r©) rYr[rar\rfrKÚmssÚ mss_numeratorÚmss_denominators rCrr¬sˆ€ô�d“/�K€Aˆ1؈1ƒuÜÐGÓHÐHØ �A‘‰,€Cð;ØŸ ™ ˆ ØŸ/™/ˆô�!”W×ÑÜ$ ]ÓDÐDÜ ˜}Ó >Ð>øô ó;ÜÐ9Ó:Ð:ð;ús ¨A+Á+Bcó•[X5up#pEUS:a [S5eX5- nURnURn[ U[5(a [Xx5$[Xx5$![a [ S5ef=f)z©Return the square root of the population variance. See ``pvariance`` for arguments and other details. >>> pstdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) 0.986893273527251 rEz'pstdev requires at least one data pointrarb) rYr^rar\rfrKrcrdres rCrrÃs„€ô�d“-�K€Aˆ1؈1ƒuÜÐGÓHÐHØ ‰&€Cð;ØŸ ™ ˆ ØŸ/™/ˆô�!”W×ÑÜ$ ]ÓDÐDÜ ˜}Ó >Ð>øô ó;ÜÐ9Ó:Ð:ð;ús ¥A(Á(A>có •[U5upp4US:a [S5eX$S- - n[U5[URUR 54$![ a% [U5[U5[U5- 4s$f=f)zFIn one pass, compute the mean and sample standard deviation as floats.r�r`rE)rorrxr©r€r�rr)rYrar\r[rKrcs rCÚ _mean_stdevrhÚs|€ä˜“Y�N€Aˆ4؈1ƒuÜÐGÓHÐHØ �A‘‰,€Cð4Ü�T‹{Ô/°· ± ¸s¿¹ÓOÐOÐOøÜ ó4ä�T‹{œE $›K¬%°«)Ñ3Ð3Ò3ð4ús¨*AÁ,BÂBreÚycóT•[X-5n[U5(dG[U5(a5[U5(d%[U5(dSn[X0-X1-5U- $U$U(d%U(aU(aSn[X0-X1-5U- $U$[ X4X*45nX$SU-- -$)zRReturn sqrt(x * y) computed with improved accuracy and without overflow/underflow.gðg€ar9)r"r*r+Ú _sqrtprodr))rerir4ÚscalerJs rCrkrkæsž€ä ˆQ‰U‹ €AÜ �A�;‰;Ü ��8‰8œE !ŸH™H¬U°1¯X©XàˆEܘU™Y¨© Ó2°UÑ:Ð :ØˆÞ Þ –ðˆEܘU™Y¨© Ó2°UÑ:Ð :؈ô ��˜˜B˜Ó €AØ �C˜!‘G‰}Ñ ÐrBcóø^^•[U5n[U5U:wa [S5eUS:a [S5e[U5U- m[U5U- m[U4SjU5U4SjU55nX2S- - $)a@Covariance Return the sample covariance of two inputs *x* and *y*. Covariance is a measure of the joint variability of two inputs. >>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> y = [1, 2, 3, 1, 2, 3, 1, 2, 3] >>> covariance(x, y) 0.75 >>> z = [9, 8, 7, 6, 5, 4, 3, 2, 1] >>> covariance(x, z) -7.5 >>> covariance(z, x) -7.5 zDcovariance requires that both inputs have same number of data pointsr�z,covariance requires at least two data pointsc3ó,># •UH oT- v• M g7frGr<)rIÚxir[s €rCrLÚcovariance..søé€Ð)¢q ˜–9¢qùóƒc3ó,># •UH oT- v• M g7frGr<©rIÚyiÚybars €rCrLrpsøé€Ð+B¸"°®IÂùrqrE)r’rr(r))rerirKÚsxyr[rus @@rCrrsvù€ô" ˆA‹€AÜ ˆ1ƒv�ƒ{ÜÐdÓeÐe؈1ƒuÜÐLÓMÐMÜ �‹7�Q‰;€DÜ �‹7�Q‰;€DÜ Ô)¡qÓ)Ô+BÁÓ+BÓ C€CØ �a‘%‰=ÐrBÚlinear)rOcó•[U5n[U5U:wa [S5eUS:a [S5eUS;a[SU<35eUS:XaUS- S- n[XS 9n[XS 9nOD[ U5U- n[ U5U- nUVs/sHowU- PM nnUVs/sHoˆU- PM nn[ X5n [ X5n [ X5n U [ X«5- $s snfs snf![a [S 5ef=f) a(Pearson's correlation coefficient Return the Pearson's correlation coefficient for two inputs. Pearson's correlation coefficient *r* takes values between -1 and +1. It measures the strength and direction of a linear relationship. >>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> y = [9, 8, 7, 6, 5, 4, 3, 2, 1] >>> correlation(x, x) 1.0 >>> correlation(x, y) -1.0 If *method* is "ranked", computes Spearman's rank correlation coefficient for two inputs. The data is replaced by ranks. Ties are averaged so that equal values receive the same rank. The resulting coefficient measures the strength of a monotonic relationship. Spearman's rank correlation coefficient is appropriate for ordinal data or for continuous data that doesn't meet the linear proportion requirement for Pearson's correlation coefficient. zEcorrelation requires that both inputs have same number of data pointsr�z-correlation requires at least two data points>rwÚrankedrRryrEr¦r»z&at least one of the inputs is constant)r’rrr�r(r)rkrÕ) rerirOrKrŒr[rurortrvrnÚsyys rCrrs€ô. ˆA‹€AÜ ˆ1ƒv�ƒ{ÜÐeÓfÐf؈1ƒuÜÐMÓNÐNØ Ð)Ó)ÜÐ+¨F©:Ð6Ó7Ð7Ø �ÓØ�Q‘˜"‘ ˆÜ �!Ñ !ˆÜ �!Ñ !‰ä�A‹w˜‰{ˆÜ�A‹w˜‰{ˆÙ!"Ó #¢˜2�$ŒY¡ˆÐ #Ù!"Ó #¢˜2�$ŒY¡ˆÐ #Ü �!‹-€CÜ �!‹-€CÜ �!‹-€CðHØ”Y˜sÓ(Ñ(Ð(ùò $ùÚ #øô óHÜÐFÓGÐGðHús C!Â!C&à C+Ã+DÚLinearRegression©ÚslopeÚ intercept)Ú proportionalcó¢^ •[U5n[U5U:wa [S5eUS:a [S5eU(d<[U5U- n[U5U- m UVs/sHoUU- PM nnU 4SjU5n[X5S-n[X5nXg- nU(aSOT UW-- n [ X‰S9$s snf![a [S5ef=f)aOSlope and intercept for simple linear regression. Return the slope and intercept of simple linear regression parameters estimated using ordinary least squares. Simple linear regression describes relationship between an independent variable *x* and a dependent variable *y* in terms of a linear function: y = slope * x + intercept + noise where *slope* and *intercept* are the regression parameters that are estimated, and noise represents the variability of the data that was not explained by the linear regression (it is equal to the difference between predicted and actual values of the dependent variable). The parameters are returned as a named tuple. >>> x = [1, 2, 3, 4, 5] >>> noise = NormalDist().samples(5, seed=42) >>> y = [3 * x[i] + 2 + noise[i] for i in range(5)] >>> linear_regression(x, y) #doctest: +ELLIPSIS LinearRegression(slope=3.17495..., intercept=1.00925...) If *proportional* is true, the independent variable *x* and the dependent variable *y* are assumed to be directly proportional. The data is fit to a line passing through the origin. Since the *intercept* will always be 0.0, the underlying linear function simplifies to: y = slope * x + noise >>> y = [3 * x[i] + noise[i] for i in range(5)] >>> linear_regression(x, y, proportional=True) #doctest: +ELLIPSIS LinearRegression(slope=2.90475..., intercept=0.0) zKlinear regression requires that both inputs have same number of data pointsr�z3linear regression requires at least two data pointsc3ó,># •UH oT- v• M g7frGr<rss €rCrLÚ$linear_regression..�søé€Ð #¢˜2�$ŽY¢ùrqrÆz x is constantr|)r’rr(r)rÕr{) rerirrKr[rorvrnr}r~rus @rCr r RsÙø€ôL ˆA‹€AÜ ˆ1ƒv�ƒ{ÜÐkÓlÐl؈1ƒuÜÐSÓTÐTÞ Ü�A‹w˜‰{ˆÜ�A‹w˜‰{ˆÙ!"Ó #¢˜2�$ŒY¡ˆÐ #Ü #¡Ó #ˆÜ �!‹-˜#Ñ €CÜ �!‹-€Cð/Ø‘ ˆö$‘¨°¸± Ñ)<€IÜ  %Ñ =Ð=ùò $øô ó/ܘoÓ.Ð.ð/úsÁB3ÂB8Â8Ccóò•US- n[U5S::amSX3-- nSU-S-U-S-U-S-U-S-U-S -U-S -U-S -U-nS U-S -U-S-U-S-U-S-U-S-U-S-U-S-nXV- nXU--$US::aUOSU- n[[U5*5nUS::a^US- nSU-S-U-S-U-S-U-S-U-S-U-S-U-S-nSU-S -U-S!-U-S"-U-S#-U-S$-U-S%-U-S-nO]US- nS&U-S'-U-S(-U-S)-U-S*-U-S+-U-S,-U-S--nS.U-S/-U-S0-U-S1-U-S2-U-S3-U-S4-U-S-nXV- nUS:aU*nXU--$)5Nrüg333333Û?g…ëQ¸Ç?g^’}o)š£@gäE.kÒRà@g �·Ulð@g*u›†>læ@gçNÍØÑÊ@gÌÀ"]Ξ@gnC‹ˆ¤`@guïžÙ @giK˜Ê~j´@gv®±|EÜ@g¾ôdª|1ã@gfRÖÕr·Ô@gŸÈu.2µ@g÷³Èý~y…@gµn8(E@rýrÆg@gš™™™™™ù?g鬷ÀZaI?ggìElëD—?g7\¸¹«òÎ?g²uSÌSô?gÄ=Ë. @gj%b÷@g›±ÊHw…@gjRéýeÆö?gä9dh? >g('ß¿ŒñA?g¿«~z �?g@ð”3õÂ?gÉ…3ò’æ?g3fRæxÒú?gI¤F»ïl@g“¿“ÖtûŠ>g*àYÌÆnü>gESB\T?gçN;A+›?gÏUR1ÙúÒ?gE¤F¦Žü?gP‡nêÚ@g&å>Á±¡@g�Áøñ¿iâg¿tcI,\ó>g×Å�—¼ÈI?g*F2ùvŽ?gûC4ë†Á?g×ÇOÓ1ã?)r#r"r')Úpr^Úsigmar¨ÚrrÂrÃres rCÚ_normal_dist_inv_cdfr‡�s€ð ˆC‰€AÜ ˆAƒw�%ÓØ �q‘uÑ ˆà0°1Ñ4Ø0ñ1Ø45ñ6à0ñ1à45ñ6ð1ñ1ð56ñ6ð1ñ 1ð56ñ 6ð 1ñ 1ð 56ñ 6ð 1ñ 1ð 56ñ 6ð1ñ1ð56ñ6ˆð1°1Ñ4Ø0ñ1Ø45ñ6à0ñ1à45ñ6ð1ñ1ð56ñ6ð1ñ 1ð56ñ 6ð 1ñ 1ð 56ñ 6ð 1ñ 1ð 56ñ 6ðñˆð ‰IˆØ˜‘YÑÐØ �#‹X‰˜3 ™7€AÜ Œc�!‹fˆW‹ €A؈CƒxØ �‰Gˆà1°AÑ5Ø1ñ2Ø56ñ7à1ñ2à56ñ7ð2ñ2ð67ñ7ð2ñ 2ð67ñ 7ð 2ñ 2ð 67ñ 7ð 2ñ 2ð 67ñ 7ð2ñ2ˆð2°AÑ5Ø1ñ2Ø56ñ7à1ñ2à56ñ7ð2ñ2ð67ñ7ð2ñ 2ð67ñ 7ð 2ñ 2ð 67ñ 7ð 2ñ 2ð 67ñ 7ðñ‰ð �‰Gˆà1°AÑ5Ø1ñ2Ø56ñ7à1ñ2à56ñ7ð2ñ2ð67ñ7ð2ñ 2ð67ñ 7ð 2ñ 2ð 67ñ 7ð 2ñ 2ð 67ñ 7ð2ñ2ˆð3°QÑ6Ø1ñ2Ø56ñ7à1ñ2à56ñ7ð2ñ2ð67ñ7ð2ñ 2ð67ñ 7ð 2ñ 2ð 67ñ 7ð 2ñ 2ð 67ñ 7ðñˆð ‰ €A؈3ƒwØ ˆBˆØ �U‘Ñ ÐrB)r‡có•\rSrSrSrSSS.rS"Sjr\S5rSS .S jr S r S r S r S#Sjr SrSr\S5r\S5r\S5r\S5r\S5rSrSrSrSrSrSr\rSr\rSrSr Sr!S r"S!r#Sr$g)$riàz(Normal distribution of a random variablez(Arithmetic mean of a normal distributionz+Standard deviation of a normal distribution©Ú_muÚ_sigmacóf•US:a [S5e[U5Ul[U5Ulg)zDNormalDist where mu is the mean and sigma is the standard deviation.rÆzsigma must be non-negativeN)rrxrŠr‹)Úselfr^r…s rCÚ__init__ÚNormalDist.__init__ês+€à �3‹;Ü!Ð">Ó?Ð ?ܘ“9ˆŒÜ˜E“lˆ� rBcó•U"[U56$)z5Make a normal distribution instance from sample data.)rh)ÚclsrYs rCÚ from_samplesÚNormalDist.from_samplesñs€ñ”K Ó%Ð&Ð&rBN©Úseedcóþ•Uc[RO[R"U5Rn[nURnURn[ SU5Vs/sHot"U"5XV5PM sn$s snf)z=Generate *n* samples for a given mean and standard deviation.N)ÚrandomÚRandomr‡rŠr‹r)r�rKr•ÚrndÚinv_cdfr^r…r—s rCÚsamplesÚNormalDist.samplesös^€à#™|Œf�mŠm´·²¸tÓ1D×1KÑ1KˆÜ&ˆØ �X‰XˆØ— ‘ ˆÜ39¸$À´?ÓC²?¨a�™›˜rÖ)±?ÑCÐCùÒCsÁ A:cóÀ•URUR-nU(d [S5eXR- n[X3-SU-- 5[ [ U-5- $)z4Probability density function. P(x <= X < x+dx) / dxz$pdf() not defined when sigma is zerogÀ)r‹rrŠr$r"r&)r�rerÚdiffs rCr9ÚNormalDist.pdfþsR€à—;‘; §¡Ñ,ˆÞÜ!Ð"HÓIÐ IØ—8‘8‰|ˆÜ�4‘; $¨¡/Ñ2Ó3´d¼3À¹>Ó6JÑJÐJrBcóœ•UR(d [S5eSS[XR- UR[-- 5--$)z,Cumulative distribution function. P(X <= x)z$cdf() not defined when sigma is zerorürý)r‹rr%rŠÚ_SQRT2©r�res rCr@ÚNormalDist.cdfs>€à�{�{Ü!Ð"HÓIÐ IØ�cœC §X¡X¡°$·+±+ÄÑ2FÑ GÓHÑHÑIÐIrBcóp•US::dUS:¼a [S5e[XRUR5$)a#Inverse cumulative distribution function. x : P(X <= x) = p Finds the value of the random variable such that the probability of the variable being less than or equal to that value equals the given probability. This function is also called the percent point function or quantile function. rÆrýz$p must be in the range 0.0 < p < 1.0)rr‡rŠr‹)r�r„s rCršÚNormalDist.inv_cdf s2€ð �‹8�q˜C“xÜ!Ð"HÓIÐ IÜ# A§x¡x°·±Ó=Ð=rBcóf•[SU5Vs/sHo RX!- 5PM sn$s snf)aFDivide into *n* continuous intervals with equal probability. Returns a list of (n - 1) cut points separating the intervals. Set *n* to 4 for quartiles (the default). Set *n* to 10 for deciles. Set *n* to 100 for percentiles which gives the 99 cuts points that separate the normal distribution in to 100 equal sized groups. rE)rSrš)r�rKr•s rCrÚNormalDist.quantiless+€ô.3°1°a¬[Ó9ª[¨— ‘ ˜Q™UÖ#©[Ñ9Ð9ùÒ9s�.c ó4•[U[5(d [S5eXp2URUR4URUR4:aX2p2UR UR pTU(aU(d [ S5eXT- n[URUR- 5nU(d%S[USUR-[-- 5- $URU-URU-- nURUR-[Xw-U[XT- 5--5-n X‰-U- n X‰- U- n S[URU 5URU 5- 5[URU 5URU 5- 5-- $)azCompute the overlapping coefficient (OVL) between two normal distributions. Measures the agreement between two normal probability distributions. Returns a value between 0.0 and 1.0 giving the overlapping area in the two underlying probability density functions. >>> N1 = NormalDist(2.4, 1.6) >>> N2 = NormalDist(3.2, 2.0) >>> N1.overlap(N2) 0.8035050657330205 z$Expected another NormalDist instancez(overlap() not defined when sigma is zerorýr9) r¿rryr‹rŠrrr#r%r¡r"r'r@) r�ÚotherÚXÚYÚX_varÚY_varÚdvr¶r¡ÚbÚx1Úx2s rCÚoverlapÚNormalDist.overlap%sN€ô ˜%¤×,Ñ,ÜÐBÓCÐ C؈1Ø �H‰H�a—e‘eÐ  §¡¨!¯%©%Ð0Ó 0؈qØ—z‘z 1§:¡:ˆuÞžEÜ!Ð"LÓMÐ MØ ‰]ˆÜ �!—%‘%˜!Ÿ%™%‘-Ó ˆÞØœ˜R 3¨¯©¡>´FÑ#:Ñ;Ó<Ñ<Ð <Ø �E‰E�E‰M˜AŸE™E E™MÑ )ˆØ �H‰H�q—x‘xÑ ¤$ r¡w°´c¸%¹-Ó6HÑ1HÑ'HÓ"IÑ IˆØ‰e�r‰\ˆØ‰e�r‰\ˆØ”d˜1Ÿ5™5 ›9 q§u¡u¨R£yÑ0Ó1´D¸¿¹¸r»ÀQÇUÁUÈ2ÃYÑ9NÓ4OÑOÑPÐPrBcóp•UR(d [S5eXR- UR- $)z¡Compute the Standard Score. (x - mean) / stdev Describes *x* in terms of the number of standard deviations above or below the mean of the normal distribution. z'zscore() not defined when sigma is zero)r‹rrŠr¢s rCÚzscoreÚNormalDist.zscoreGs,€ð�{�{Ü!Ð"KÓLÐ LØ—H‘H‘  § ¡ Ñ+Ð+rBcó•UR$)z+Arithmetic mean of the normal distribution.©rŠ©r�s rCr ÚNormalDist.meanRó €ð�x‰xˆrBcó•UR$)z,Return the median of the normal distributionr¸r¹s rCr ÚNormalDist.medianWr»rBcó•UR$)z�Return the mode of the normal distribution The mode is the value x where which the probability density function (pdf) takes its maximum value. r¸r¹s rCrÚNormalDist.mode\s €ð�x‰xˆrBcó•UR$)z.Standard deviation of the normal distribution.©r‹r¹s rCrÚNormalDist.stdeves€ð�{‰{ÐrBcó4•URUR-$)z!Square of the standard deviation.rÁr¹s rCrÚNormalDist.variancejs€ð�{‰{˜TŸ[™[Ñ(Ð(rBcóô•[U[5(aA[URUR-[URUR55$[URU-UR5$)a:Add a constant or another NormalDist instance. If *other* is a constant, translate mu by the constant, leaving sigma unchanged. If *other* is a NormalDist, add both the means and the variances. Mathematically, this works only if the two distributions are independent or if they are jointly normally distributed. ©r¿rrŠr!r‹©r°r±s rCÚ__add__ÚNormalDist.__add__oóR€ô �bœ*× %Ñ %ܘbŸf™f r§v¡v™o¬u°R·Y±YÀÇ Á Ó/JÓKÐ Kܘ"Ÿ&™& 2™+ r§y¡yÓ1Ð1rBcóô•[U[5(aA[URUR- [URUR55$[URU- UR5$)aCSubtract a constant or another NormalDist instance. If *other* is a constant, translate by the constant mu, leaving sigma unchanged. If *other* is a NormalDist, subtract the means and add the variances. Mathematically, this works only if the two distributions are independent or if they are jointly normally distributed. rÆrÇs rCÚ__sub__ÚNormalDist.__sub__}rÊrBcó`•[URU-UR[U5-5$)z�Multiply both mu and sigma by a constant. Used for rescaling, perhaps to change measurement units. Sigma is scaled with the absolute value of the constant. ©rrŠr‹r#rÇs rCÚ__mul__ÚNormalDist.__mul__‹ó&€ô ˜"Ÿ&™& 2™+ r§y¡y´4¸³8Ñ';Ó<Ðr?r@rKÚ __slots__rŽÚ classmethodr’r›r9r@ršrr²rµÚpropertyr r rrrrÈrÌrÐrÔrÙrÜÚ__radd__rßÚ__rmul__rãrçrërîròrAr<rBrCrràs †Ù.ð :Ø?ñ€Iô #ðñ'óð'ð"&õDòKòJò >ô :ò QòD ,ðñóððñóððñóððñóððñ)óð)ò 2ò 2ò=ò=ò-ò.ð€Hòð€Hò;ò -òPò%õ&rBrcó ^^^^•UUUU4SjnU$)Ncóž>•T"U5n[T"U5U- =n5T:”a)XT"U5- -n[T"U5U- =n5T:”aM)U$)u=Return x such that f(x) ≈ y within the specified tolerance.r)rireržrãÚf_inv_estimateÚf_primeÚ tolerances €€€€rCÚf_invÚ_newton_raphson..f_invÂsYø€á ˜1Ó ˆÜ™!˜A›$ ™(Ð"�$Ó# iÓ/Ø ™ › Ñ"Ñ "ˆAô™!˜A›$ ™(Ð"�$Ó# iÕ/àˆrBr<)rûrãrürýrþs```` rCÚ_newton_raphsonrÁsû€÷ðð €LrBcóš•US::aSU4OSSU- 4upSU-S-S- nUSs=:¼aS:aO X!-$US[S U-S -5-- nX!-$) Nrürýçð¿r9gáðé¼¹AÛ?gü©ñÒMbp?gV-²�ïß?gMÕp£^v›?gÔÚ$2h@g_ó€ÄÛ@r-©r„Úsignres rCÚ_quartic_invcdf_estimaterÊsk€Ø˜s›(ˆs�A‰h¨¨s°Q©w¨�G€DØ ˆq‰�_Ñ$ sÑ*€A؈EÕ�EÕà ‰8€Oð ˆ[œ3˜{¨Q™Ð1AÑAÓBÑ BÑBˆØ ‰8€OrBcó6•SUS--SUS--- SU--S-$r!r<rs rCrørøÓs'€�$˜˜A™‘+  a¨¡d¡ Ñ*¨U°Q©YÑ6¸Ò•[[U[-S- 55$)Nr�)r'r/r,rs rCrørøãs€œœS ¤R¡¨¡›]Ô+rBcó•SU-S- $©Nr�rEr<rs rCrørøäs €˜Q˜q™S 1šWrBcóP•S[[SU-S- 5[-S- 5-$)Nr�rEr£)r-r3r,rs rCrørøås$€˜1œs¤D¨¨1©¨Q©£K´"Ñ$4¸Ñ#9Ó:Ò:rBcóX•US:a[SU-5S- $S[SSU-- 5- $)Nrür�rE)r"rs rCrørøès/€¨Q°«WœD  1¡›I¨™MÐK¸!¼dÀ1ÀqÈÁsÁ7»mÑ:KÐKrBcó8•S[SU-S- 5-[- $r)r1r,rs rCrørøés€˜œD  1¡ q¡›MÑ)¬BÒ.rB) rìrÿrr rrr#rr*ròr r rrrrr”có ^^^^^ •[T5nU(d [S5e[TS[[45(d [ S5eTS::a[ST<35e[ RU5mTc[SU<35e[RU5nURm URmUUUUU 4SjnST<S U<3Ul U$) a<Return a function that makes a random selection from the estimated probability density function created by kde(data, h, kernel). Providing a *seed* allows reproducible selections within a single thread. The seed may be an integer, float, str, or bytes. A StatisticsError will be raised if the *data* sequence is empty. Example: >>> data = [-2.1, -1.3, -0.4, 1.9, 5.1, 6.2] >>> rand = kde_random(data, h=1.5, seed=8675309) >>> new_selections = [rand() for i in range(10)] >>> [round(x, 1) for x in new_selections] [0.7, 6.2, 1.2, 6.9, 7.0, 1.8, 2.5, -0.5, -1.8, 5.6] rïrrðrÆrñr.có6>•T"T5TT"T"55--$rGr<)ÚchoicerYr4Ú kernel_invcdfr—s€€€€€rCÚrandÚkde_random..randsø€Ù�d‹|˜a¡-±³Ó"9Ñ9Ñ9Ð9rBzRandom KDE selection with h=rJ) r’rr¿rXrxryÚ_kernel_invcdfsrQÚ_randomr˜r—rrK) rYr4rLr•rKÚprngrrrr—s `` @@@rCr r ðsÆü€ô$ ˆD‹ €AÞ ÜÐ3Ó4Ð4ä �d˜1‘g¤¤U˜|× ,Ñ ,ÜÐCÓDÐDàˆCƒxÜÐ EÀ1Á&ÐIÓJÐJä#×'Ñ'¨Ó/€MØÑÜÐ 5°f±ZÐ@ÓAÐAä �>‰>˜$Ó €DØ �[‰[€FØ �[‰[€F÷:ñ:ð3°©v°]¸6¹+ÐF€D„Là €KrBrG)znegative value)rý)rì)gê-�™—q=)drKÚ__all__rsrÓr—ÚsysÚ fractionsrÚdecimalrÚ itertoolsrrrÚbisectrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3Ú functoolsr4Úoperatorr5Ú collectionsr6r7r8r¡rrrrbrortrWrTr„r‡r“rxr�rXr¢Ú float_infoÚmant_digr¤Ú__annotations__r©r·r rrrr rrrrrr rrrrrrhrkrrr{r r‡Ú _statisticsÚ ImportErrorrrrÚ_quartic_invcdfr Ú_triweight_invcdfršrr r<rBrCÚr.s±ðòhòT €ó2 ÛÛ Û åÝß,Ñ,ß,ßE×EÕEßK×K×KÝÝß8Ñ8á ˆc‹€Ø €ô �jô ò 3ôl&òR ò4ò>+ò\ô$ð¨°IÀQò3È4ÐPUÉ;õ3ðl ð¨ð°ôð˜3Ÿ>™>×2Ñ2Ñ2°QÑ6€�Ó6ð #˜3ð # 3ð #¨5ô #ð˜Sð Sð¨Wôò<"ô,!òH ôF5,òp+ò0 ò,ô&E+òPBò<Kð(Q°öQðr ;õ-4ôl)%ôX&ôR?ô.?ò. 4ð�ð˜5ð Uôò:ð8$,õ-Hñ`Ð0Ð2HÓIÐð05õ7>òzGðV Ý0÷ \&ñ\&ôBòñ"Ø-Ù<Ù2ñ4€ò ñ $Ø/ÙAÙ2ñ4Ðñ ‹l×"Ñ"Ù*Ù+Ù$Ù:ØØ"ÙKÙ.ñ €ð+¨8Ñ4€�ÑØ,¨]Ñ;€� ÑØ"1°+Ñ">€�ÑØ-¨iÑ8€� Ñð)°÷)øðió Ùð úsÅ0G*Ç*G3Ç2G3