Python
Python copied to clipboard
Implement XGBoost Classifier and Regressor from Scratch [Pls label me for Hacktoberfest-24]
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:
- Bug Fixes: Resolved issues in the implementations of the XGBoost Classifier and Regressor by correcting data handling, model training, and prediction functionalities.
- Doctests: Added and updated doctests for both algorithms to ensure proper functionality and ease of understanding.
- 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:
-
XGBoost Classifier:
- Corrected the
data_handlingfunction to ensure it properly splits the dataset into features and targets, now returning a tuple of appropriate types. - Fixed the
xgboostfunction to ensure it correctly fits the model with the provided features and target data, ensuring it utilizes the XGBoost library appropriately. - Updated the
mainfunction to include proper handling and display of the confusion matrix, providing visual insights into model performance.
- Corrected the
-
XGBoost Regressor:
- Similar updates were made to the
data_handlingfunction to handle input data correctly. - Adjusted the
xgboostfunction to ensure proper training of the regression model and make predictions on the test dataset. - Enhanced the
mainfunction to calculate and display mean absolute error and mean square error for model evaluation.
- Similar updates were made to the
These changes enhance the functionality of the algorithms, providing a more robust and reliable implementation for users.