Calculation of standard deviation and correlation coefficient in Python

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

Calculation of standard deviation and correlation coefficient in Python
Time comparison: Correlation coefficient calculation in Python
[python] Calculation of months and years of difference in datetime
[Python] Calculation of Kappa (k) coefficient
Calculation of Spearman's rank correlation coefficient
[Statistics for programmers] Variance, standard deviation and coefficient of variation
[Algorithm x Python] Calculation of basic statistics Part3 (range, variance, standard deviation, coefficient of variation)
[Python] Calculation of image similarity (Dice coefficient)
Project Euler # 1 "Multiples of 3 and 5" in Python
Explanation of edit distance and implementation in Python
Date calculation in python
Date calculation in Python
"Linear regression" and "Probabilistic version of linear regression" in Python "Bayesian linear regression"
Experience the good calculation efficiency of vectorization in Python
Full-width and half-width processing of CSV data in Python
Receives and outputs standard output of Python 2 and Python 3> C implementations
Difference between Ruby and Python in terms of variables
Calculate mean, median, mode, variance, standard deviation in Python
Start numerical calculation in Python (with Homebrew and pip)
Overview of generalized linear models and implementation in Python
Sample of getting module name and class name in Python
Summary of date processing in Python (datetime and dateutil)
[Python] Types of statistical values (features) and calculation methods
[Python] How to handle inf and NaN in numpy mean, standard deviation, maximum / minimum
Shapley value calculation in Python
Equivalence of objects in Python
Transposed matrix in Python standard
Stack and Queue in Python
Unittest and CI in Python
Implementation of quicksort in Python
Source installation and installation of Python
[Python of Hikari-] Chapter 08-03 Module (Import and use of standard library)
[Python] Heron's formula functionalization and calculation of the maximum area
Applied practice of try/except and dictionary editing and retrieval in Python
[For beginners] Summary of standard input in Python (with explanation)
Reference order of class variables and instance variables in "self. Class variables" in Python
A standard way to develop and distribute packages in Python
Comparison of how to use higher-order functions in Python 2 and 3
[Introduction to Scipy] Calculation of Lorenz curve and Gini coefficient ♬
[Python] Strengths and weaknesses of DataFrame in terms of time required
[Tips] Problems and solutions in the development of python + kivy
Find the average / standard deviation of the brightness values in the image
Coordination of each process in MPI and buffering of standard output
Environment construction of python and opencv
The story of Python and the story of NaN
MIDI packages in Python midi and pretty_midi
Count the number of Thai and Arabic characters well in Python
I compared the calculation time of the moving average written in Python
Difference between == and is in python
Installation of SciPy and matplotlib (Python)
[Machine learning] Understand from mathematics that standardization results in an average of 0 and a standard deviation of 1.
View photos in Python and html
Quantum chemistry calculation in Python (Psi4)
Sorting algorithm and implementation in Python
Division of timedelta in Python 2.7 series
Manipulate files and folders in Python
MySQL-automatic escape of parameters in python
About dtypes in Python and Cython
Accelerometer Alan Variance Calculation in Python
Handling of JSON files in Python
Read the standard output of a subprocess line by line in Python