def fit(self, embeddings: torch.Tensor) -> bool:
        """Fit the KDE classifier to training embeddings.

        Applies PCA, scales the features, and fits the KDE model.

        Args:
            embeddings: Training embeddings of shape (N, D)

        Returns:
            bool: True if fitting succeeded, False if insufficient samples

        Example:
            >>> classifier = KDEClassifier()
            >>> embeddings = torch.randn(1000, 512)
            >>> success = classifier.fit(embeddings)
            >>> assert success
        """
        if embeddings.shape[0] < self.n_pca_components:
            logger.info("Not enough features to commit. Not making a model.")
            return False

        # if max training points is non-zero and smaller than number of staged features, select random subset
        if embeddings.shape[0] > self.max_training_points:
            selected_idx = torch.tensor(
                random.sample(range(embeddings.shape[0]), self.max_training_points),
                device=embeddings.device,
            )
            selected_features = embeddings[selected_idx]
        else:
            selected_features = embeddings

        feature_stack = self.pca_model.fit_transform(selected_features)
        feature_stack, max_length = self.pre_process(feature_stack)
        self.max_length = max_length
        self.kde_model.fit(feature_stack)

        return True
Fit the KDE classifier to training embeddings.

        Applies PCA, scales the features, and fits the KDE model.

        Args:
            embeddings: Training embeddings of shape (N, D)

        Returns:
            bool: True if fitting succeeded, False if insufficient samples

        Example:
            >>> classifier = KDEClassifier()
            >>> embeddings = torch.randn(1000, 512)
            >>> success = classifier.fit(embeddings)
            >>> assert success
        
src/anomalib/models/components/classification/kde_classifier.py