yobx.sklearn.decomposition.sparse_pca#

yobx.sklearn.decomposition.sparse_pca.sklearn_sparse_pca(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: SparsePCA | MiniBatchSparsePCA, X: str, name: str = 'sparse_pca') str[source]#

Converts a sklearn.decomposition.SparsePCA or sklearn.decomposition.MiniBatchSparsePCA into ONNX.

The transformation replicates sklearn.decomposition.SparsePCA.transform():

  1. Centre the data by subtracting the per-feature mean stored in mean_.

  2. Apply the pre-computed projection matrix W via a single matrix multiplication, where W is derived from the fitted dictionary components_ and the regularisation parameter ridge_alpha:

W = {\mathbf{C}}^{\top}
    \bigl(\mathbf{C}\,{\mathbf{C}}^{\top} + \alpha\,\mathbf{I}\bigr)^{-1}

with \mathbf{C} = components_ and \alpha = ridge_alpha.

The full graph is:

X  ──Sub(mean_)──►  centered  ──MatMul(W)──►  output
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes defined by scikit-learn

  • estimator – a fitted SparsePCA or MiniBatchSparsePCA

  • outputs – desired output names (sparse codes)

  • X – input tensor name

  • name – prefix name for the added nodes

Returns:

output tensor name