kfda icon indicating copy to clipboard operation
kfda copied to clipboard

Update kfda.py

Open shahedahmed2023 opened this issue 11 months ago • 0 comments

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:

  1. Fixes deprecated features:

    • Updates OneHotEncoder usage to specify sparse_output parameter
    • Replaces scipy.sparse.eye with numpy.eye for better compatibility
  2. 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
  3. 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.

shahedahmed2023 avatar Feb 13 '25 22:02 shahedahmed2023