polars_online.gram.correlation¶
- polars_online.gram.correlation(g: Gram) Any[source]¶
Compute the correlation matrix of a Gram’s columns from their co-moments.
Use it to read how a Gram’s columns move together, or to pass a correlation matrix on to
polars_online.corr, whose functions read a Gram this way themselves. To judge whether a fit on the columns is determined, usevif()orcondition().Parameters
gThe Gram, as
gram()returns it, in any of its forms.
Returns
A
k x kfloat array, withkthe number of columns:C_ij / sqrt(C_ii C_jj)from the co-momentsC. Its entries arenanin the row and the column of a constant column, the intercept included: a constant has no correlation with anything, and reporting 0 there would read as “independent”. The diagonal is 1, to rounding, where the variance is above 0.Examples
This code reads
dffrom Example data:spec = po.spec.ew_cov("cov", features=["x0", "x1", "x2"], half_life=100.0) bank = po.ModelBank([spec]) bank.fit_predict(df) g = bank.gram("cov")[0] print(g["columns"]) print(po.gram.correlation(g).round(2))
['x0', 'x1', 'x2'] [[ 1. 0.16 0.08] [ 0.16 1. -0.01] [ 0.08 -0.01 1. ]]
See also
vif()andcondition(), which diagnose the same design.polars_online.corr, which repairs, summarizes and scores a correlation matrix.Is the fit determined? in docs/GRAM.md, the theory, and Check that a fit is determined, a recipe that runs.
Notes
The diagonal is
C_ii / sqrt(C_ii)**2, which came within 2.2e-16 of 1 on 200 random matrices.