def covariance(x, y):
    """
    Whereas variance measures how a single variable deviates from its mean, 
    covariance measures how two variables vary in tandem from their means.
    
    A "large" positive covariance means that x tends to be large when  y is large 
    and small when y is small. A "large" negative covariance means the opposite - 
    that x tends to be small when y is large and vice versa. A covariance close to 
    zero means no such relationship exists.
    """
    n = len(x)
    return dot(de_mean(x), de_mean(y)) / (n - 1)
def covariance(x, y):
    """
    Whereas variance measures how a single variable deviates from its mean, 
    covariance measures how two variables vary in tandem from their means.
    
    A "large" positive covariance means that x tends to be large when  y is large 
    and small when y is small. A "large" negative covariance means the opposite - 
    that x tends to be small when y is large and vice versa. A covariance close to 
    zero means no such relationship exists.
    """
    n = len(x)
    return dot(de_mean(x), de_mean(y)) / (n - 1)
def total_sum_of_squares(y):
    """the total squared variation of y_i's from their mean"""
    return sum(v ** 2 for v in de_mean(y))
def covariance(x, y):
    n = len(x)
    return dot(de_mean(x), de_mean(y)) / (n - 1)
Exemple #5
0
def total_sum_of_squares(y):
    """the total squared variation of y_i's from their mean"""
    return sum(v**2 for v in de_mean(y))