﻿# cuML PCA in inference: transform new batches in the fitted basis instead of fitting again

Preserve cuML PCA fitted components, centering and feature order for inference, separating transform from fit_transform and preventing evaluation-data leakage.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-cuml-pca-fit-transform-serving-basis/
Language: en

## Treat projection coordinates as model state

A GPU preprocessing service reduces embedding dimensions before applying a trained classifier. Its helper calls fit_transform on each incoming batch because that method conveniently returns an array. The [cuML PCA reference](https://docs.nvidia.com/cuml/latest/api/generated/cuml.decomposition.PCA/) separates fitting components from transforming new data. A newly fitted basis can assign different meaning to the output coordinates. The downstream classifier expects the basis used during its own training, not merely an array with the same reduced dimension.

## Preserve centering and feature order together

The fitted components operate on a specific ordered input feature space and its learned centering. A source-column permutation or changed embedding revision can invalidate that meaning while preserving shape. Record the input representation with the PCA artifact. Validate the actual feature order at the boundary instead of assuming a dataframe conversion or array export preserves the desired schema. The projection's numerical dimensions are insufficient evidence that the input coordinates still represent the same quantities.

## Use transform for the fixed projection contract

The [scikit-learn PCA reference](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html) describes transform as projection onto components previously extracted from training data. Apply that distinction when reviewing the GPU implementation. Serving the same observation in a different batch should not silently retrain its coordinate system. If adaptation to a new population is intended, make it a new fitted model revision and validate the downstream consumer against that revision rather than treating adaptation as routine inference.

## Keep evaluation data outside fitting

The [scikit-learn pitfalls guide](https://scikit-learn.org/stable/common_pitfalls.html) warns against fitting preprocessing on evaluation data. A dimensionality reducer learns population structure even without target labels. Restrict fitting to the declared training data and apply the resulting transformation to held-out observations. Repeatedly fitting on evaluation batches can both change coordinates and contaminate the meaning of the experiment, so a correct output shape cannot establish that the evaluation procedure remained valid.

## Test invariance to unrelated batch members

With a fixed fitted artifact, compare the transformed representation of an observation when evaluated alone and alongside other valid observations, allowing appropriate numerical tolerance. Confirm artifact reload and feature-schema checks as well. The guides on [logical feature schemas](/journal/data-guide-frictionless-table-schema/) and [distribution drift evidence](/journal/data-guide-evidently-schema-population-drift/) provide related context. A population shift may motivate a new training decision, but it should not covertly change the coordinate system of every inference batch through an accidental fit call.
