github.com/goplus/llgo@v0.8.3/py/statistics/gen.go (about)

     1  package statistics
     2  
     3  import (
     4  	_ "unsafe"
     5  
     6  	"github.com/goplus/llgo/py"
     7  )
     8  
     9  const LLGoPackage = "py.statistics"
    10  
    11  // Error function at x.
    12  //
    13  //go:linkname Erf py.erf
    14  func Erf(x *py.Object) *py.Object
    15  
    16  // Return the sample arithmetic mean of data.
    17  //
    18  //	>>> mean([1, 2, 3, 4, 4])
    19  //	2.8
    20  //
    21  //	>>> from fractions import Fraction as F
    22  //	>>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)])
    23  //	Fraction(13, 21)
    24  //
    25  //	>>> from decimal import Decimal as D
    26  //	>>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")])
    27  //	Decimal('0.5625')
    28  //
    29  //	If ``data`` is empty, StatisticsError will be raised.
    30  //
    31  //go:linkname Mean py.mean
    32  func Mean(data *py.Object) *py.Object
    33  
    34  // Convert data to floats and compute the arithmetic mean.
    35  //
    36  //	This runs faster than the mean() function and it always returns a float.
    37  //	If the input dataset is empty, it raises a StatisticsError.
    38  //
    39  //	>>> fmean([3.5, 4.0, 5.25])
    40  //	4.25
    41  //
    42  //go:linkname Fmean py.fmean
    43  func Fmean(data *py.Object, weights *py.Object) *py.Object
    44  
    45  // Convert data to floats and compute the geometric mean.
    46  //
    47  //	Raises a StatisticsError if the input dataset is empty,
    48  //	if it contains a zero, or if it contains a negative value.
    49  //
    50  //	No special efforts are made to achieve exact results.
    51  //	(However, this may change in the future.)
    52  //
    53  //	>>> round(geometric_mean([54, 24, 36]), 9)
    54  //	36.0
    55  //
    56  //go:linkname GeometricMean py.geometric_mean
    57  func GeometricMean(data *py.Object) *py.Object
    58  
    59  // Return the harmonic mean of data.
    60  //
    61  //	The harmonic mean is the reciprocal of the arithmetic mean of the
    62  //	reciprocals of the data.  It can be used for averaging ratios or
    63  //	rates, for example speeds.
    64  //
    65  //	Suppose a car travels 40 km/hr for 5 km and then speeds-up to
    66  //	60 km/hr for another 5 km. What is the average speed?
    67  //
    68  //	    >>> harmonic_mean([40, 60])
    69  //	    48.0
    70  //
    71  //	Suppose a car travels 40 km/hr for 5 km, and when traffic clears,
    72  //	speeds-up to 60 km/hr for the remaining 30 km of the journey. What
    73  //	is the average speed?
    74  //
    75  //	    >>> harmonic_mean([40, 60], weights=[5, 30])
    76  //	    56.0
    77  //
    78  //	If ``data`` is empty, or any element is less than zero,
    79  //	``harmonic_mean`` will raise ``StatisticsError``.
    80  //
    81  //go:linkname HarmonicMean py.harmonic_mean
    82  func HarmonicMean(data *py.Object, weights *py.Object) *py.Object
    83  
    84  // Return the median (middle value) of numeric data.
    85  //
    86  //	When the number of data points is odd, return the middle data point.
    87  //	When the number of data points is even, the median is interpolated by
    88  //	taking the average of the two middle values:
    89  //
    90  //	>>> median([1, 3, 5])
    91  //	3
    92  //	>>> median([1, 3, 5, 7])
    93  //	4.0
    94  //
    95  //go:linkname Median py.median
    96  func Median(data *py.Object) *py.Object
    97  
    98  // Return the low median of numeric data.
    99  //
   100  //	When the number of data points is odd, the middle value is returned.
   101  //	When it is even, the smaller of the two middle values is returned.
   102  //
   103  //	>>> median_low([1, 3, 5])
   104  //	3
   105  //	>>> median_low([1, 3, 5, 7])
   106  //	3
   107  //
   108  //go:linkname MedianLow py.median_low
   109  func MedianLow(data *py.Object) *py.Object
   110  
   111  // Return the high median of data.
   112  //
   113  //	When the number of data points is odd, the middle value is returned.
   114  //	When it is even, the larger of the two middle values is returned.
   115  //
   116  //	>>> median_high([1, 3, 5])
   117  //	3
   118  //	>>> median_high([1, 3, 5, 7])
   119  //	5
   120  //
   121  //go:linkname MedianHigh py.median_high
   122  func MedianHigh(data *py.Object) *py.Object
   123  
   124  // Estimates the median for numeric data binned around the midpoints
   125  //
   126  //	of consecutive, fixed-width intervals.
   127  //
   128  //	The *data* can be any iterable of numeric data with each value being
   129  //	exactly the midpoint of a bin.  At least one value must be present.
   130  //
   131  //	The *interval* is width of each bin.
   132  //
   133  //	For example, demographic information may have been summarized into
   134  //	consecutive ten-year age groups with each group being represented
   135  //	by the 5-year midpoints of the intervals:
   136  //
   137  //	    >>> demographics = Counter({
   138  //	    ...    25: 172,   # 20 to 30 years old
   139  //	    ...    35: 484,   # 30 to 40 years old
   140  //	    ...    45: 387,   # 40 to 50 years old
   141  //	    ...    55:  22,   # 50 to 60 years old
   142  //	    ...    65:   6,   # 60 to 70 years old
   143  //	    ... })
   144  //
   145  //	The 50th percentile (median) is the 536th person out of the 1071
   146  //	member cohort.  That person is in the 30 to 40 year old age group.
   147  //
   148  //	The regular median() function would assume that everyone in the
   149  //	tricenarian age group was exactly 35 years old.  A more tenable
   150  //	assumption is that the 484 members of that age group are evenly
   151  //	distributed between 30 and 40.  For that, we use median_grouped().
   152  //
   153  //	    >>> data = list(demographics.elements())
   154  //	    >>> median(data)
   155  //	    35
   156  //	    >>> round(median_grouped(data, interval=10), 1)
   157  //	    37.5
   158  //
   159  //	The caller is responsible for making sure the data points are separated
   160  //	by exact multiples of *interval*.  This is essential for getting a
   161  //	correct result.  The function does not check this precondition.
   162  //
   163  //	Inputs may be any numeric type that can be coerced to a float during
   164  //	the interpolation step.
   165  //
   166  //go:linkname MedianGrouped py.median_grouped
   167  func MedianGrouped(data *py.Object, interval *py.Object) *py.Object
   168  
   169  // Return the most common data point from discrete or nominal data.
   170  //
   171  //	``mode`` assumes discrete data, and returns a single value. This is the
   172  //	standard treatment of the mode as commonly taught in schools:
   173  //
   174  //	    >>> mode([1, 1, 2, 3, 3, 3, 3, 4])
   175  //	    3
   176  //
   177  //	This also works with nominal (non-numeric) data:
   178  //
   179  //	    >>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
   180  //	    'red'
   181  //
   182  //	If there are multiple modes with same frequency, return the first one
   183  //	encountered:
   184  //
   185  //	    >>> mode(['red', 'red', 'green', 'blue', 'blue'])
   186  //	    'red'
   187  //
   188  //	If *data* is empty, ``mode``, raises StatisticsError.
   189  //
   190  //go:linkname Mode py.mode
   191  func Mode(data *py.Object) *py.Object
   192  
   193  // Return a list of the most frequently occurring values.
   194  //
   195  //	Will return more than one result if there are multiple modes
   196  //	or an empty list if *data* is empty.
   197  //
   198  //	>>> multimode('aabbbbbbbbcc')
   199  //	['b']
   200  //	>>> multimode('aabbbbccddddeeffffgg')
   201  //	['b', 'd', 'f']
   202  //	>>> multimode('')
   203  //	[]
   204  //
   205  //go:linkname Multimode py.multimode
   206  func Multimode(data *py.Object) *py.Object
   207  
   208  // Divide *data* into *n* continuous intervals with equal probability.
   209  //
   210  //	Returns a list of (n - 1) cut points separating the intervals.
   211  //
   212  //	Set *n* to 4 for quartiles (the default).  Set *n* to 10 for deciles.
   213  //	Set *n* to 100 for percentiles which gives the 99 cuts points that
   214  //	separate *data* in to 100 equal sized groups.
   215  //
   216  //	The *data* can be any iterable containing sample.
   217  //	The cut points are linearly interpolated between data points.
   218  //
   219  //	If *method* is set to *inclusive*, *data* is treated as population
   220  //	data.  The minimum value is treated as the 0th percentile and the
   221  //	maximum value is treated as the 100th percentile.
   222  //
   223  //go:linkname Quantiles py.quantiles
   224  func Quantiles(data *py.Object) *py.Object
   225  
   226  // Return the sample variance of data.
   227  //
   228  //	data should be an iterable of Real-valued numbers, with at least two
   229  //	values. The optional argument xbar, if given, should be the mean of
   230  //	the data. If it is missing or None, the mean is automatically calculated.
   231  //
   232  //	Use this function when your data is a sample from a population. To
   233  //	calculate the variance from the entire population, see ``pvariance``.
   234  //
   235  //	Examples:
   236  //
   237  //	>>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]
   238  //	>>> variance(data)
   239  //	1.3720238095238095
   240  //
   241  //	If you have already calculated the mean of your data, you can pass it as
   242  //	the optional second argument ``xbar`` to avoid recalculating it:
   243  //
   244  //	>>> m = mean(data)
   245  //	>>> variance(data, m)
   246  //	1.3720238095238095
   247  //
   248  //	This function does not check that ``xbar`` is actually the mean of
   249  //	``data``. Giving arbitrary values for ``xbar`` may lead to invalid or
   250  //	impossible results.
   251  //
   252  //	Decimals and Fractions are supported:
   253  //
   254  //	>>> from decimal import Decimal as D
   255  //	>>> variance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")])
   256  //	Decimal('31.01875')
   257  //
   258  //	>>> from fractions import Fraction as F
   259  //	>>> variance([F(1, 6), F(1, 2), F(5, 3)])
   260  //	Fraction(67, 108)
   261  //
   262  //go:linkname Variance py.variance
   263  func Variance(data *py.Object, xbar *py.Object) *py.Object
   264  
   265  // Return the population variance of “data“.
   266  //
   267  //	data should be a sequence or iterable of Real-valued numbers, with at least one
   268  //	value. The optional argument mu, if given, should be the mean of
   269  //	the data. If it is missing or None, the mean is automatically calculated.
   270  //
   271  //	Use this function to calculate the variance from the entire population.
   272  //	To estimate the variance from a sample, the ``variance`` function is
   273  //	usually a better choice.
   274  //
   275  //	Examples:
   276  //
   277  //	>>> data = [0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25]
   278  //	>>> pvariance(data)
   279  //	1.25
   280  //
   281  //	If you have already calculated the mean of the data, you can pass it as
   282  //	the optional second argument to avoid recalculating it:
   283  //
   284  //	>>> mu = mean(data)
   285  //	>>> pvariance(data, mu)
   286  //	1.25
   287  //
   288  //	Decimals and Fractions are supported:
   289  //
   290  //	>>> from decimal import Decimal as D
   291  //	>>> pvariance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")])
   292  //	Decimal('24.815')
   293  //
   294  //	>>> from fractions import Fraction as F
   295  //	>>> pvariance([F(1, 4), F(5, 4), F(1, 2)])
   296  //	Fraction(13, 72)
   297  //
   298  //go:linkname Pvariance py.pvariance
   299  func Pvariance(data *py.Object, mu *py.Object) *py.Object
   300  
   301  // Return the square root of the sample variance.
   302  //
   303  //	See ``variance`` for arguments and other details.
   304  //
   305  //	>>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])
   306  //	1.0810874155219827
   307  //
   308  //go:linkname Stdev py.stdev
   309  func Stdev(data *py.Object, xbar *py.Object) *py.Object
   310  
   311  // Return the square root of the population variance.
   312  //
   313  //	See ``pvariance`` for arguments and other details.
   314  //
   315  //	>>> pstdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])
   316  //	0.986893273527251
   317  //
   318  //go:linkname Pstdev py.pstdev
   319  func Pstdev(data *py.Object, mu *py.Object) *py.Object
   320  
   321  // Covariance
   322  //
   323  //	Return the sample covariance of two inputs *x* and *y*. Covariance
   324  //	is a measure of the joint variability of two inputs.
   325  //
   326  //	>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
   327  //	>>> y = [1, 2, 3, 1, 2, 3, 1, 2, 3]
   328  //	>>> covariance(x, y)
   329  //	0.75
   330  //	>>> z = [9, 8, 7, 6, 5, 4, 3, 2, 1]
   331  //	>>> covariance(x, z)
   332  //	-7.5
   333  //	>>> covariance(z, x)
   334  //	-7.5
   335  //
   336  //go:linkname Covariance py.covariance
   337  func Covariance(x *py.Object, y *py.Object) *py.Object
   338  
   339  // Pearson's correlation coefficient
   340  //
   341  //	Return the Pearson's correlation coefficient for two inputs. Pearson's
   342  //	correlation coefficient *r* takes values between -1 and +1. It measures
   343  //	the strength and direction of a linear relationship.
   344  //
   345  //	>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
   346  //	>>> y = [9, 8, 7, 6, 5, 4, 3, 2, 1]
   347  //	>>> correlation(x, x)
   348  //	1.0
   349  //	>>> correlation(x, y)
   350  //	-1.0
   351  //
   352  //	If *method* is "ranked", computes Spearman's rank correlation coefficient
   353  //	for two inputs.  The data is replaced by ranks.  Ties are averaged
   354  //	so that equal values receive the same rank.  The resulting coefficient
   355  //	measures the strength of a monotonic relationship.
   356  //
   357  //	Spearman's rank correlation coefficient is appropriate for ordinal
   358  //	data or for continuous data that doesn't meet the linear proportion
   359  //	requirement for Pearson's correlation coefficient.
   360  //
   361  //go:linkname Correlation py.correlation
   362  func Correlation(x *py.Object, y *py.Object) *py.Object
   363  
   364  // Slope and intercept for simple linear regression.
   365  //
   366  //	Return the slope and intercept of simple linear regression
   367  //	parameters estimated using ordinary least squares. Simple linear
   368  //	regression describes relationship between an independent variable
   369  //	*x* and a dependent variable *y* in terms of a linear function:
   370  //
   371  //	    y = slope * x + intercept + noise
   372  //
   373  //	where *slope* and *intercept* are the regression parameters that are
   374  //	estimated, and noise represents the variability of the data that was
   375  //	not explained by the linear regression (it is equal to the
   376  //	difference between predicted and actual values of the dependent
   377  //	variable).
   378  //
   379  //	The parameters are returned as a named tuple.
   380  //
   381  //	>>> x = [1, 2, 3, 4, 5]
   382  //	>>> noise = NormalDist().samples(5, seed=42)
   383  //	>>> y = [3 * x[i] + 2 + noise[i] for i in range(5)]
   384  //	>>> linear_regression(x, y)  #doctest: +ELLIPSIS
   385  //	LinearRegression(slope=3.09078914170..., intercept=1.75684970486...)
   386  //
   387  //	If *proportional* is true, the independent variable *x* and the
   388  //	dependent variable *y* are assumed to be directly proportional.
   389  //	The data is fit to a line passing through the origin.
   390  //
   391  //	Since the *intercept* will always be 0.0, the underlying linear
   392  //	function simplifies to:
   393  //
   394  //	    y = slope * x + noise
   395  //
   396  //	>>> y = [3 * x[i] + noise[i] for i in range(5)]
   397  //	>>> linear_regression(x, y, proportional=True)  #doctest: +ELLIPSIS
   398  //	LinearRegression(slope=3.02447542484..., intercept=0.0)
   399  //
   400  //go:linkname LinearRegression py.linear_regression
   401  func LinearRegression(x *py.Object, y *py.Object) *py.Object