(pairs: Iterable[Tuple[float, float]])
| 26 | |
| 27 | |
| 28 | def pearson(pairs: Iterable[Tuple[float, float]]) -> float: |
| 29 | xs, ys = zip(*pairs) |
| 30 | x_mean = sum(xs) / len(xs) |
| 31 | y_mean = sum(ys) / len(ys) |
| 32 | numerator = sum((x - x_mean) * (y - y_mean) for x, y in zip(xs, ys)) |
| 33 | x_den = math.sqrt(sum((x - x_mean) ** 2 for x in xs)) |
| 34 | y_den = math.sqrt(sum((y - y_mean) ** 2 for y in ys)) |
| 35 | if x_den <= 0 or y_den <= 0: |
| 36 | return 0.0 |
| 37 | return numerator / (x_den * y_den) |
| 38 | |
| 39 | |
| 40 | def ranks(values: List[float]) -> List[float]: |
no outgoing calls
no test coverage detected