Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

""" 

Collection of tools for managing and analysisng linear models 

 

Todo 

----- 

Consider what functionality we actually want here 

 

""" 

 

import numpy as np 

from collections import namedtuple 

 

 

ScatterData = namedtuple('ScatterData', ['target', 'predicted']) 

 

 

def compute_correlation_matrix(A): 

""" 

Computes correlation matrix for rows in matrix. 

 

Notes 

----- 

Naive implementation. 

 

Parameters 

---------- 

A : NumPy array 

fit matrix 

 

Returns 

------- 

NumPy array 

correlation matrix 

""" 

N = A.shape[0] 

C = np.zeros((N, N)) 

for i in range(N): 

for j in range(i+1, N): 

norm = np.linalg.norm(A[i, :]) * np.linalg.norm(A[j, :]) 

c_ij = np.dot(A[i, :], A[j, :]) / norm 

C[i, j] = c_ij 

C[j, i] = c_ij 

return C