diff --git a/python/cuml/cuml/decomposition/pca.pyx b/python/cuml/cuml/decomposition/pca.pyx index 10d3eb6eee..b59dadc7c1 100644 --- a/python/cuml/cuml/decomposition/pca.pyx +++ b/python/cuml/cuml/decomposition/pca.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2023, NVIDIA CORPORATION. +# Copyright (c) 2019-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -632,8 +632,9 @@ class PCA(UniversalBase, self.components_ *= cp.sqrt(self.n_samples_ - 1) self.components_ /= self.singular_values_.reshape((-1, 1)) - X = X - self.mean_ - X_transformed = X.dot(self.components_.T) + precomputed_mean_impact = self.mean_ @ self.components_.T + mean_impact = cp.ones((X.shape[0], 1)) @ precomputed_mean_impact.reshape(1, -1) + X_transformed = X.dot(self.components_.T) -mean_impact if self.whiten: self.components_ *= self.singular_values_.reshape((-1, 1))