PCA weighted by observations (samples) is described in this exchange on Cross Validated.
Feasibly, it can be performed by taking a weight vector of shape (n_rows, 1) and copying it into multiple columns. What was originally, say,
is now
0.25 0.25 0.25
0.25 0.25 0.25
0.5 0.5 0.5
using the following function:
def make_weights_matrix(weights, X):
if weights.shape[0] != X.shape[0]:
raise ValueError("weights {} and X {} must have same length.".format(weights.shape, X.shape))
w_new = np.empty_like(X)
w_new[:] = weights
return w_new
w = make_weights_matrix(weights, df)
This could be avoided if the package supported broadcasting, rather than having utils perform numerous checks to assure that weights and X have the same shape. Additionally, the einsum logic would have to be circumvented since the broadcasting should be built-in.
PCA weighted by observations (samples) is described in this exchange on Cross Validated.
Feasibly, it can be performed by taking a weight vector of shape
(n_rows, 1)and copying it into multiple columns. What was originally, say,is now
using the following function:
This could be avoided if the package supported broadcasting, rather than having
utilsperform numerous checks to assure thatweightsandXhave the same shape. Additionally, theeinsumlogic would have to be circumvented since the broadcasting should be built-in.