Python icon indicating copy to clipboard operation
Python copied to clipboard

Implement XGBoost Classifier and Regressor from Scratch [Pls label me for Hacktoberfest-24]

Open Dhairya-A-Mehra opened this issue 1 year ago • 0 comments

Describe your change:

  • [ ] Add an algorithm?
  • [x] Fix a bug or typo in an existing algorithm?
  • [x] Add or change doctests?
  • [ ] Documentation change?

Checklist:

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized.
  • [x] I know that pull requests will not be merged if they fail the automated tests.
  • [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [x] All new Python files are placed inside an existing directory.
  • [x] All filenames are in all lowercase characters with no spaces or dashes.
  • [x] All functions and variable names follow Python naming conventions.
  • [x] All function parameters and return values are annotated with Python type hints.
  • [x] 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".

Summary of Changes:

  1. Bug Fixes: Resolved issues in the implementations of the XGBoost Classifier and Regressor by correcting data handling, model training, and prediction functionalities.
  2. Doctests: Added and updated doctests for both algorithms to ensure proper functionality and ease of understanding.
  3. Code Optimization: Improved code readability and organization, adhering to Python naming conventions and best practices.

Detailed Explanation:

In this pull request, I have made significant modifications to both the xgboost_classifier.py and xgboost_regressor.py files:

  1. XGBoost Classifier:

    • Corrected the data_handling function to ensure it properly splits the dataset into features and targets, now returning a tuple of appropriate types.
    • Fixed the xgboost function to ensure it correctly fits the model with the provided features and target data, ensuring it utilizes the XGBoost library appropriately.
    • Updated the main function to include proper handling and display of the confusion matrix, providing visual insights into model performance.
  2. XGBoost Regressor:

    • Similar updates were made to the data_handling function to handle input data correctly.
    • Adjusted the xgboost function to ensure proper training of the regression model and make predictions on the test dataset.
    • Enhanced the main function to calculate and display mean absolute error and mean square error for model evaluation.

These changes enhance the functionality of the algorithms, providing a more robust and reliable implementation for users.

Dhairya-A-Mehra avatar Oct 01 '24 16:10 Dhairya-A-Mehra