Credit Approval Simulator
Fill in the fields below to simulate credit approval.
✅ Credit Approved
📉 Default Risk: 2.37%
💰 Estimated Income: R$ 39,000.00
📊 Provided Score: 1000 (Grade: A)
🏦 Applied Interest Rate: 7.49%
Most Influential Factors in this Simulation
About the Project
This project is an interactive credit approval simulator developed as part of my Data Science and Machine Learning portfolio. The system uses a trained XGBoost Classifier model to estimate the probability of default based on financial and personal information of the applicant.
⚙️ How it works
The user fills a form with data like age, income, loan amount, purpose and credit history. These inputs go through an automated preprocessing pipeline, where they are transformed and standardized according to the trained model. Then, the model makes the prediction and the site displays:
- ✅ Credit Approval Status;
- 📉 Estimated Probability of Default;
- 💸 Estimated Annual Income;
- 🧾 The Credit Score and Grade (A–G);
- 💰 The Interest Rate Applied Automatically Based on the Grade.
🧩 Data Modeling and Preparation
The model was trained on historical credit application
data containing demographic and financial variables.
During data preparation:
- The column
person_emp_length(employment length) was removed due to high missing values and low relevance; - The variable
loan_percent_incomewas replaced byloan_to_income_ratio, representing the ratio between the requested amount and annual income — a more interpretable and stable metric; - Missing interest rates were automatically filled with the median of each
loan_grade; - The variable
scale_pos_weightwas adjusted to balance classes and improve sensitivity (recall) for the minority class (defaults).
Median interest rates applied per credit grade:
- A: 7.49%
- B: 10.99%
- C: 13.48%
- D: 15.31%
- E: 16.82%
- F: 18.53%
- G: 20.11%
This approach allowed the model to learn the natural relationship between credit grade and interest rate, reflecting the real behavior of the financial market.
🤖 Machine Learning Model
After testing various supervised algorithms (Random Forest, Gradient Boosting, Logistic Regression, SGDClassifier and XGBoost), the XGBoost Classifier was selected as the final model due to its best balance between accuracy, recall and stability.
Model main configurations:
XGBClassifier(
n_estimators=2000, # Total tree count;
learning_rate=0.08, # Learning Rate;
max_depth=6, # Max depth per tree;
min_child_weight=1, # Min sum of instance weight needed in a child;
subsample=0.9, # Sampling to reduce overfitting;
colsample_bytree=0.8, # Fraction of columns used by each tree;
random_state=42, # Reproducibility;
tree_method="hist", # Method optimized for CPU;
scale_pos_weight=ratio, # Minority class balancing;
eval_metric="aucpr" # Prioritize precision in recall of defaults
)
📊 Model Performance:
- Accuracy: ≈ 93%
- F1-Score: ~0.82
- AUC (Area under ROC curve): 0.95
The final model was calibrated and adjusted for practical use in the simulator, ensuring consistent predictions even with small variations in input data.
🌐 Integration with the Website
The integration was done with Flask, using a dedicated Blueprint for the credit simulator.
The route /projects/credit_simulator loads the model and the preprocessor once, ensuring performance and efficiency.
The execution flow is simple and direct:
- The user fills out the form on the site.
- The data is transformed by the saved preprocessor (
preprocessor_simulador.pkl). - The model (
XGBClassifier_simulador.pkl) performs the prediction. - The result is displayed with approval, default risk and complementary financial information.
🎨 Visual Interface
The interface was built with Bootstrap 5 and Jinja2, maintaining a clean and modern aesthetic inspired by financial dashboards.
- Centered and responsive form;
- Persistent fields after submission (maintains the typed values);
- Visual feedback with colors and icons — green (approved), red (denied), yellow (high risk);
- Layout adapted for mobile devices and desktops.
📂 Files Structure
ml_models/
├── model_train_simulador.py # Model Train Script
├── model_predict_simulador.py # Functions for loading and prediction
├── preprocessor_simulador.pkl # Saved preprocessor
├── feature_columns_simulador.pkl # List of used columns
├── XGBClassifier_simulador.pkl # Final trained model
└── taxas_por_grade.pkl # Median rates table by grade
templates/
└── projects/
└── credit_simulator.html # Simulator HTML Template
views.py # Blueprint Flask (routes)
app.py # Main Flask Application
🚀 Technologies Used
- Python (pandas, scikit-learn, XGBoost, joblib)
- Flask (backend and routes management)
- Bootstrap 5 (responsive interface)
- HTML + Jinja2 (dynamic rendering)
- Render (deployment and hosting of the portfolio)
📊 Demo
The simulator allows testing different credit scenarios by changing variables such as monthly income, loan amount and score. The results are displayed intuitively, as in the example:
✅ Credit Approved
Default Risk: 9.49%
Estimated Annual Income: R$ 52.000,00
Score Provided: 600 (Grade D)
Applied Interest Rate: 15.31%