Created
July 15, 2013 15:36
-
-
Save zacstewart/6000932 to your computer and use it in GitHub Desktop.
Linear kernel matrix inversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> K = X.dot(X.transpose()) | |
>>> K | |
array([[ 2, 3, 3, 5, 5, 6], | |
[ 3, 5, 4, 8, 7, 9], | |
[ 3, 4, 5, 7, 8, 9], | |
[ 5, 8, 7, 13, 12, 15], | |
[ 5, 7, 8, 12, 13, 15], | |
[ 6, 9, 9, 15, 15, 18]]) | |
>>> np.linalg.inv(K) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/Users/zacstewart/Code/kaggle_belkin/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 445, in inv | |
return wrap(solve(a, identity(a.shape[0], dtype=a.dtype))) | |
File "/Users/zacstewart/Code/kaggle_belkin/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 328, in solve | |
raise LinAlgError('Singular matrix') | |
numpy.linalg.linalg.LinAlgError: Singular matrix | |
>>> np.linalg.pinv(K) | |
array([[ 0.00068587, 0.00102881, 0.00102881, 0.00171468, 0.00171468, | |
0.00205761], | |
[ 0.00102881, 0.12654321, -0.12345679, 0.12757202, -0.12242798, | |
0.00308642], | |
[ 0.00102881, -0.12345679, 0.12654321, -0.12242798, 0.12757202, | |
0.00308642], | |
[ 0.00171468, 0.12757202, -0.12242798, 0.12928669, -0.12071331, | |
0.00514403], | |
[ 0.00171468, -0.12242798, 0.12757202, -0.12071331, 0.12928669, | |
0.00514403], | |
[ 0.00205761, 0.00308642, 0.00308642, 0.00514403, 0.00514403, | |
0.00617284]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment