def cov(xs, ys): """共分散""" n = len(xs) avg_x = mean.mean(xs) avg_y = mean.mean(ys) xs = map(lambda x: x - avg_x, xs) ys = map(lambda x: x - avg_y, ys) return sum(x * y for x, y in zip(xs, ys)) / n
def ssd(xs): """偏差平方和 sum of squared deviation """ avg = mean.mean(xs) return sum(map(lambda x: (x - avg) ** 2, xs))
def test_mean(xs, expected): assert mean.mean(xs) == expected assert mean.mean(xs) == stats.mean(xs)