Skip to content

Improved PDF Classification Model Using XGBoost - #20

Merged
SeanClay10 merged 5 commits into
mainfrom
feature/xgboost-classification
Nov 21, 2025
Merged

SeanClay10 merged 5 commits into
mainfrom
feature/xgboost-classification

Conversation

@SeanClay10

Copy link
Copy Markdown
Collaborator

Updated the document classification pipeline to replace the previous model with an XGBoost binary classifier trained on TF-IDF features. The update improves predictive accuracy, probability calibration, and robustness on small and imbalanced datasets. The classification script, training pipeline, and test suite were all updated to load XGBoost models, probability outputs, and confidence reporting. Pytest unit tests were enhanced to validate model loading, training behavior, and expected outcomes.

Key Enhancements

  1. Migration to XGBoost (binary:logistic)
  • Implemented an XGBoost classifier configured for binary document usefulness prediction.
  • The model now outputs a calibrated probability representing confidence that a document is “useful.”
  • The new approach handles sparse TF-IDF vectors efficiently and generalizes better on small datasets compared to previous linear models.
  1. Improved Training Pipeline
    Reworked train_model.py to:
  • Load raw training text and labels.
  • Encode labels using LabelEncoder.
  • Convert documents into TF-IDF features using up to 10,000 weighted terms across unigrams, bigrams, and trigrams.
  • Create XGBoost DMatrices for efficient GPU/CPU training.
  • Stratified train/test splitting ensures evaluation remains balanced and representative.

@SeanClay10 SeanClay10 self-assigned this Nov 20, 2025
@SeanClay10
SeanClay10 force-pushed the feature/xgboost-classification branch from c7d567f to 667c96a Compare November 20, 2025 21:25

@raymondcen raymondcen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lower iterations. 1000 iterations with max depth of 6 is too much and model will overfit and training will take too long with 600+ files unless we add multi threading. If not you can also add an early stopping parameter to it there's probably something equivalent to that with XGBoost. It finishes the training immediately if it doesn't improve after k rounds.

Add 'subsample' parameter to also mitigate memorization.

Consider adding L1 and L2 parameter or something equivalent. I forget which but one shrinks down confident predictions and another removes weak predictions. They basically help in overfitting. Makes it focus on more data driven patterns.

Small things:
You can add the 'verbose' parameter onto it an it should show/print the progress it's training at every round. That way you can also see which parmeter is working and which is not.

You can also add 'scale_pos_weight' parameter to it when we get a more balanced data set.

Other than those things it looks good. The parameters are mainly for the future when we even out the 'not useful' class but they would still be helpful currently (maybe not the scale_pos_weight though).

@SeanClay10
SeanClay10 merged commit 39d637d into main Nov 21, 2025
2 checks passed
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.

2 participants