I calculated the standard deviation and the correlation coefficient by several methods.
Python 3.5.2rc1 (default, Jun 13 2016, 09:33:26)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = [1, 2, 3, 4, 5]
>>> y = [0, 2, 4, 5, 8]
Use the statistics library. Built in from Python-3.4 (?).
>>> import statistics
>>> statistics.pstdev(x), statistics.stdev(x)
(1.4142135623730951, 1.5811388300841898)
numpy
>>> import numpy
>>> numpy.std(x), numpy.std(x, ddof=1)
(1.4142135623730951, 1.5811388300841898)
Is scipy the same as numpy?
>>> import scipy
>>> scipy.std(x), scipy.std(x, ddof=1)
(1.4142135623730951, 1.5811388300841898)
Calculate the correlation coefficient with numpy.
>>> numpy.corrcoef(x, y)[0, 1]
0.99044346677110506
Then scipy.
>>> import scipy.stats
>>> scipy.stats.pearsonr(x, y)
(0.99044346677110517, 0.0011198526620164956)
Is scipy the most convenient?
Recommended Posts