Below is the code:
import numpy as np
import pandas as pd
def correlation(x, y):
std_x = (x - x.mean())/x.std(ddof = 0)
std_y = (y - y.mean())/y.std(ddof = 0)
return (std_x * std_y).mean
a = pd.Series([2, 4, 5, 7, 9])
b = pd.Series([12, 10, 9, 7, 3])
ca = correlation(a, b)
print(ca)
It does not return a correlation value, instead it returns a series with keys like 0 ,1, 2, 3, 4, 5values like -1.747504, -0.340844, -0.043282, -0.259691, -2.531987.
Please help me understand the problem behind this.
source
share