Goulib.stats module¶
very basic statistics functions
-
Goulib.stats.mean_var(data)[source]¶ mean and variance by stable algorithm :param :return: float (mean, variance) of data uses a stable algo by Knuth
-
Goulib.stats.avg(data)¶ Returns: mean of data
-
Goulib.stats.variance(data)[source]¶ Returns: variance of data, faster (?) if mean is already available
-
Goulib.stats.var(data)¶ Returns: variance of data, faster (?) if mean is already available
-
Goulib.stats.confidence_interval(data, conf=0.95)[source]¶ Returns: (low,high) bounds of 95% confidence interval of data
-
class
Goulib.stats.Stats(data=[], mean=None, var=None)[source]¶ Bases:
objectan object that computes mean, variance and modes of data that is appended to it as in a list (but actual values are not stored)
-
__init__(data=[], mean=None, var=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
sum¶
-
sum1¶
-
sum2¶
-
mean¶
-
avg¶
-
average¶
-
mu¶
-
variance¶
-
var¶
-
stddev¶
-
sigma¶
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__¶ Return str(self).
-
-
class
Goulib.stats.Discrete(data)[source]¶ Bases:
Goulib.stats.Statsdiscrete probability density function
Parameters: data – can be: - list of equiprobable values (uniform distribution)
- dict of x:p values:probability pairs
-
__init__(data)[source]¶ Parameters: data – can be: - list of equiprobable values (uniform distribution)
- dict of x:p values:probability pairs
-
__add__(other)¶
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__mul__(other)¶
-
__ne__¶ Return self!=value.
-
__neg__()¶
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__pow__(n)¶
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__()¶ Return repr(self).
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__¶ Return str(self).
-
__sub__(other)¶
-
append(x)¶ add data x to Stats
-
average¶
-
avg¶
-
covariance(other)¶
-
extend(data)¶
-
mean¶
-
mu¶
-
remove(data)¶ remove data from Stats :param data: value or iterable of values
-
sigma¶
-
stddev¶
-
sum¶
-
sum1¶
-
sum2¶
-
var¶
-
variance¶
-
class
Goulib.stats.PDF(pdf, data=[])[source]¶ Bases:
Goulib.expr.Expr,Goulib.stats.Statsprobability density function
-
__init__(pdf, data=[])[source]¶ Parameters: f – function or operator, Expr to copy construct, or formula string
-
__add__(right)¶
-
__and__(right)¶
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__div__(right)¶
-
__eq__(other)¶ Return self==value.
-
__float__()¶
-
__format__()¶ Default object formatter.
-
__ge__(other)¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__(other)¶ Return self>value.
-
__hash__= None¶
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__invert__()¶
-
__le__(other)¶ Return self<=value.
-
__lshift__(dx)¶
-
__lt__(other)¶ Return self<value.
-
__mul__(right)¶
-
__ne__(other)¶ Return self!=value.
-
__neg__()¶
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__or__(right)¶
-
__pow__(right)¶
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__()¶ Return repr(self).
-
__rmul__(right)¶
-
__rshift__(dx)¶
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__()¶ Return str(self).
-
__sub__(right)¶
-
__truediv__(right)¶
-
__xor__(right)¶
-
append(x)¶ add data x to Stats
-
applx(f, var='x')¶ function composition f o self = self(f(x))
-
apply(f, right=None)¶ function composition self o f = f(self(x))
-
average¶
-
avg¶
-
complexity()¶ measures the complexity of Expr :return: int, sum of the precedence of used ops
-
covariance(other)¶
-
extend(data)¶
-
html(**kwargs)¶
-
isNum¶
-
isconstant¶ Returns: True if Expr evaluates to a constant number or bool
-
latex()¶ Returns: string LaTex formula
-
mean¶
-
mu¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
points(xmin=-1, xmax=1, step=0.1)¶ Returns: x,y lists of float : points for a line plot
-
remove(data)¶ remove data from Stats :param data: value or iterable of values
-
render(fmt='svg', **kwargs)¶
-
save(filename, **kwargs)¶
-
sigma¶
-
stddev¶
-
sum¶
-
sum1¶
-
sum2¶
-
svg(**kwargs)¶
-
var¶
-
variance¶
-
-
class
Goulib.stats.Normal(data=[], mean=0, var=1)[source]¶ Bases:
Goulib.stats.PDFrepresents a normal distributed variable the base class (list) optionally contains data
if data is specified, it it used to fit a normal law
-
__truediv__(a)¶
-
cov(other)¶
-
correlation(other)¶
-
corr(other)¶
-
__and__(right)¶
-
__call__(x=None, **kwargs)¶ evaluate the Expr at x OR compose self(x())
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__(other)¶ Return self==value.
-
__float__()¶
-
__format__()¶ Default object formatter.
-
__ge__(other)¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__(other)¶ Return self>value.
-
__hash__= None¶
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__invert__()¶
-
__le__(other)¶ Return self<=value.
-
__lshift__(dx)¶
-
__lt__(other)¶ Return self<value.
-
__ne__(other)¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__or__(right)¶
-
__pow__(right)¶
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__()¶ Return repr(self).
-
__rmul__(right)¶
-
__rshift__(dx)¶
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__xor__(right)¶
-
append(x)¶ add data x to Stats
-
applx(f, var='x')¶ function composition f o self = self(f(x))
-
apply(f, right=None)¶ function composition self o f = f(self(x))
-
average¶
-
avg¶
-
complexity()¶ measures the complexity of Expr :return: int, sum of the precedence of used ops
-
extend(data)¶
-
html(**kwargs)¶
-
isNum¶
-
isconstant¶ Returns: True if Expr evaluates to a constant number or bool
-
mean¶
-
mu¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
points(xmin=-1, xmax=1, step=0.1)¶ Returns: x,y lists of float : points for a line plot
-
remove(data)¶ remove data from Stats :param data: value or iterable of values
-
render(fmt='svg', **kwargs)¶
-
save(filename, **kwargs)¶
-
sigma¶
-
stddev¶
-
sum¶
-
sum1¶
-
sum2¶
-
svg(**kwargs)¶
-
var¶
-
variance¶
-
-
Goulib.stats.linear_regression(x, y, conf=None)[source]¶ Parameters: - x,y – iterable data
- conf – float confidence level [0..1]. If None, confidence intervals are not returned
Returns: b0,b1,b2, (b0
Return the linear regression parameters and their <prob> confidence intervals.
ex: >>> linear_regression([.1,.2,.3],[10,11,11.5],0.95)