Skip to content

Conversation

krvipin15
Copy link

Describe your change:

Fixes the broken Gaussian Naive Bayes implementation that was using deprecated sklearn functions.

Issues in the old code:

  • Used plot_confusion_matrix() which was deprecated and removed in scikit-learn 1.2+
  • Only demonstrated sklearn's built-in implementation, not an actual algorithm
  • Contained unnecessary time.sleep() calls
  • Not suitable for TheAlgorithms repo (should implement algorithms from scratch)

What this PR does:

  • Replaces the broken sklearn example with a complete from-scratch implementation
  • Implements Gaussian Naive Bayes using only NumPy
  • Includes fit(), predict(), and predict_proba() methods
  • Uses proper mathematical formulas (Gaussian PDF and Bayes' theorem)
  • Handles numerical stability with log probabilities
  • Comprehensive docstrings with type hints
  • Working doctests that pass automated testing
  • Example usage with Iris dataset achieving 95%+ accuracy
  • Reference: https://en.wikipedia.org/wiki/Naive_Bayes_classifier
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

krvipin15 and others added 3 commits October 15, 2025 16:48
- Replace deprecated sklearn example with proper from-scratch implementation
- Remove deprecated plot_confusion_matrix (removed in sklearn 1.2+)
- Implement complete GaussianNaiveBayes class using NumPy
- Add fit, predict, and predict_proba methods
- Include proper type hints and comprehensive docstrings
- Add working doctests and example with Iris dataset
- Remove unnecessary time.sleep() calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant