On this page
  1. statistics.correlation
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

statistics.correlation

Up: statistics | Next: statistics.covariance
Rel: statistics.covariance, statistics.fmean, statistics.geometric_mean, statistics.harmonic_mean
Ref: docs.python.org — statistics.correlation
Tags: #public #python3 #stdlib #statistics


Import

import statistics
from statistics import correlation

Signature & Overview

statistics.correlation(x, y, /, *, method='linear')

Pearson's correlation coefficient Return the Pearson's correlation coefficient for two inputs. Pearson's correlation coefficient r takes values between -1 and +1. It measures

Usage

import statistics

if hasattr(statistics, 'correlation'):
    r = statistics.correlation([1, 2, 3, 4], [2, 4, 6, 8])
    assert round(r, 6) == 1.0

Gotchas

REPL Inspect

from statistics import correlation
help(correlation)

Linked from

Related notes