CUR¶
- class spalor.models.CUR(n_rows=10, n_cols=10, r=None)[source]¶
- Dimensionality reduction based on a low-rank matrix faactorization:
A=C*U*R
where C consists of columns sampled from A, R is rows sampled from A, and U=(C’*C)^-1 *C’ *A * R’*(R*R’)^-1.
Typically, the columns and rows are selected at random with probabilites proportional to the leverage scores.
- n_rowsint, default=10
Number of rows to sample.
- n_colsint, default=10
Number of columns to sample.
- method{‘exact’, ‘approximate’, ‘random’}, default=’leverage_scores_QR’
- method to selct rows.
“exact”: randomly select by leverage scores
“approximate” : randomly select columns by approximated leverage scores
“random” : randomly select columns
- d1int
number or rows in the original matrix
- d2int
number of columns in the original matrix
- colslist
list containing indices of columns sampled
- Cndarray, shape = (d1,n_components)
Columns sampled
- Xndarray, shape = (n_components, d2)
Score matrix, often used for classification. Coordinates in the lower dimensional column space
``` A=np.array([[1, 1, 2, 2],
[2, 1, 3, 5], [1, 2, 3, 1], [3, 1, 4, 8]], dtype=float)
cur=CUR(n_rows=2, n_cols=2) cur.fit(A)
print(“C:
- “, cur.C)
print(“U:
- “, cur.U)
print(“R:
- “, cur.R)
print(“columns used:
- “, cur.cols)
print(“rows used:
- “, cur.rows)