By my understanding, for a matrix with n samples and p features:
- Ridge regression using Cholesky decomposition takes O(p^3) time
- Ridge regression using SVD takes O(p^3) time
- Computing SVD when only the diagonal matrix is needed (and not u and v) takes O(np^2) time
I tested this out in scipy on both random and real-world data with p > n (p = 43624, n = 1750) and found ridge regression with a Cholesky decomposition to be much quicker than computing it using SVD and much quicker than just computing the diagonal matrix of the SVD. Why is this?
import numpy as np
from sklearn import linear_model
import scipy
import time
x = np.random.rand(1750, 43264)
y = np.random.rand(1750)
old_time = time.time()
clf = linear_model.Ridge(alpha=1.0, solver='cholesky')
clf.fit(x, y)
print("Time taken to solve Ridge with cholesky: ", time.time() - old_time)
old_time = time.time()
clf = linear_model.Ridge(alpha=1.0, solver='svd')
clf.fit(x, y)
print("Time taken to solve Ridge with SVD: ", time.time() - old_time)
old_time = time.time()
scipy.linalg.svd(x, full_matrices=False)
print("Time taken for SVD", time.time() - old_time)
old_time = time.time()
scipy.linalg.svd(x, full_matrices=False, compute_uv=False)
print("Time taken for SVD, just s", time.time() - old_time)
Output:
Time taken to solve Ridge with cholesky: 3.2336008548736572
Time taken to solve Ridge with SVD: 118.47378492355347
Time taken for SVD 92.01217150688171
Time taken for SVD, just s 44.7129647731781