kfda
kfda copied to clipboard
Update kfda.py
Title: Update KFDA implementation to address deprecated features and numerical stability issues
Description: This PR updates the Kernel Fisher Discriminant Analysis (KFDA) implementation to address several issues:
-
Fixes deprecated features:
- Updates OneHotEncoder usage to specify sparse_output parameter
- Replaces scipy.sparse.eye with numpy.eye for better compatibility
-
Improves numerical stability:
- Adds proper handling of edge cases in n_components calculation
- Prevents division by zero in class mean calculations
- Adds regularization to matrices for better conditioning
- Implements custom prediction to avoid NearestCentroid warnings
-
Enhances robustness:
- Handles broadcasting issues in mean centering
- Adds appropriate jitter to centroids when needed
- Updates attribute checks for better compatibility with scikit-learn
These changes maintain the same mathematical approach while making the implementation more robust across a wider range of datasets and making it compatible with newer versions of scikit-learn and scipy.
Tests have been run on various datasets to ensure the accuracy is maintained while eliminating warnings.