Simple statistical functions implemented in readable Python.
Project description
simple-statistics for Python.
simplestatistics is compatible with Python 2 & 3. ### Installation
Install the current PyPI release:
pip install simplestatistics
Or install the development version from GitHub:
pip install git+https://github.com/sheriferson/simplestatistics
Usage
>>> import simplestatistics as ss
>>> ss.mean([1, 2, 3])
2.0
>>> ss.t_test([1, 2, 2.4, 3, 0.9], 2)
-0.3461277235039042
Documentation
You can read the documentation online.
Or you can generate it yourself:
Inside simplestatistics/.
make html
Documentation will be generated in _build/html/.
Tests
If you want coverage reports, you need to have `coverage <https://pypi.python.org/pypi/coverage>`__ installed:
pip install coverage
nosetests --with-coverage --cover-package=simplestatistics --with-doctest
Otherwise, to just run the tests:
nosetests --with-doctest
Functions and examples
Descriptive statistics
Function |
Example |
---|---|
min([-3, 0, 3]) |
|
max([1, 2, 3]) |
|
sum([1, 2, 3.5]) |
|
quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], [0.25, 0.75]) |
|
product([1.25, 2.75], [2.5, 3.40]) |
Measures of central tendency
Function |
Example |
---|---|
mean([1, 2, 3]) |
|
median([10, 2, -5, -1]) |
|
mode([2, 1, 3, 2, 1]) |
|
geometric_mean([1, 10]) |
|
harmonic_mean([1, 2, 4]) |
|
root_mean_square([1, -1, 1, -1]) |
|
skew([1, 2, 5]) |
|
kurtosis([1, 2, 3, 4, 5]) |
Measures of dispersion
Function |
Example |
---|---|
variance([1, 2, 3], sample = True) |
|
standard_deviation([1, 2, 3], sample = True) |
|
coefficient_of_variation([1, 2, 3], sample = True) |
|
interquartile_range([1, 3, 5, 7]) |
|
sum_nth_power_deviations([-1, 0, 2, 4], 3) |
|
z_scores([-2, -1, 0, 1, 2], sample = True) |
Linear regression
Function |
Example |
---|---|
linear_regression([1, 2, 3, 4, 5], [4, 4.5, 5.5, 5.3, 6]) |
|
linear_regression_line([.5, 9.5])([1, 2, 3]) |
Similarity
Function |
Example |
---|---|
correlate([2, 1, 0, -1, -2, -3, -4, -5], [0, 1, 1, 2, 3, 2, 4, 5]) |
Distributions
Function |
Example |
---|---|
factorial(20) or factorial([1, 5, 20]) |
|
choose(5, 3) |
|
normal(4, 8, 2) or normal([1, 4], 8, 2) |
|
binomial(4, 12, 0.2) or binomial([3,4,5], 12, 0.5) |
|
bernoulli(0.25) |
|
poisson(3, [0, 1, 2, 3]) |
|
t_test([1, 2, 3, 4, 5, 6], 3.385) |
|
chi_squared_dist_table(k = 10, p = .01) |
Classifiers
Function |
Example |
---|---|
See documentation for examples of how to train and classify. |
|
See documentation for examples of how to train and classify. |
Errors
Function |
Example |
---|---|
error_function(1) |
Spirit and rules
Everything should be implemented in raw, organic, locally sourced Python.
Use libraries only if you have to and only when unrelated to the math/statistics. For example, from functools import reduce to make reduce available for those using python3. That’s okay, because it’s about making Python work and not about making the stats easier.
It’s okay to use operators and functions if they correspond to regular calculator buttons. For example, all calculators have a built-in square root function, so there is no need to implement that ourselves, we can use math.sqrt(). Anything beyond that, like mean, median, we have to write ourselves.
Pull requests are welcome!
Contributors
Jim Anderson (jhowardanderson)
Lidiane Taquehara (lidimayra)
Pierre-Selim (PierreSelim)
Tom MacWright (tmcw)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.