How laxmigs24/hotel-revenue-operations works
1. This repository is a small end-to-end analytics/ML system centered on one business problem: predict hotel booking cancellations and estimate revenue at risk. It has two distinct execution paths: an offline pipeline for data preparation/model training, and an online Streamlit app for decision support.
2. The raw data domain starts in data/hotel_bookings.csv and is transformed through a staged dataset chain: hotel_bookings_clean.csv after audit/deduplication, hotel_bookings_eda.csv for analysis, and hotel_bookings_feature_engineered.csv for modeling. Those files are the handoff artifacts between notebook stages.
3. The offline workflow is organized in notebooks/01_data_audit.ipynb through 04_modeling_evaluation.ipynb. These notebooks are the primary orchestration layer for exploration, feature creation, model selection, threshold tuning, and evaluation. They are not just documentation; they produce the datasets and trained model used downstream.
4. src/features.py is the architectural core of the repo. It centralizes all feature-engineering logic so the notebooks and the app use the exact same transformations. That shared module is the main boundary that prevents train/serve skew, especially for bucket labels, ordinal categories, seasonal flags, and leakage-prone fields.
5. The modeling stack is scikit-learn-based. The README indicates the final estimator is HistGradientBoostingClassifier, wrapped with preprocessing components such as OrdinalEncoder and ColumnTransformer. The model selection process compares multiple classifiers, then chooses a business threshold based on asymmetric cost rather than a pure classification metric.
6. Model evaluation is business-aware, not only statistical. The system estimates expected revenue exposure using booking value logic and selects a decision threshold assuming missed cancellations are more expensive than false alarms. Explainability is handled with permutation importance, which is used in place of SHAP in this version.
7. The app layer lives in app/streamlit_app.py and consumes the trained model bundle. It exposes four user-facing modes: single-booking prediction, explanation of one booking, batch scoring for uploaded CSVs, and a segment dashboard for portfolio-level analysis. This is the main runtime interface for hotel managers.
8. Data flow into the app is feed-forward: user input or uploaded booking data is transformed using the same feature logic in src/features.py, then passed to the trained inference pipeline, then post-processed into risk probabilities, explanations, and revenue-at-risk summaries. The app is therefore a thin presentation and scoring layer, not a separate analytics implementation.
9. tests/test_features.py acts as a guardrail around the most failure-prone part of the system: feature consistency. The tests specifically protect against category-label mismatches and ordinal encoding bugs, so the architecture has a deliberate verification layer around shared feature definitions.
10. There is also a standalone SQL/SQLite analytical subsystem under Database/ with hotel_revenue.sql and hotel_revenue.db. This is separate from the Python ML pipeline and demonstrates relational analysis, views, CTEs, window functions, and SQL-based revenue/cancellation calculations. It is best viewed as an auxiliary analytics layer rather than a production dependency of the Streamlit app.
11. The repository’s key boundary is between “feature definition” and “model/app usage.” Everything that affects the model input schema should flow through src/features.py; everything user-facing should consume the serialized model artifact rather than re-deriving logic. That separation is the main architectural safeguard in the project.
12. In diagram terms, the system is: raw booking data and SQL assets on one side; notebook-driven preparation and model training in the middle; a shared feature module and trained model artifact as the bridge; and a Streamlit decision-support app plus regression tests on the delivery side.
Main entry points: features.py Features · 01_data_audit.ipynb Data audit · 03_feature_eng.ipynb Feature eng · 04_modeling_evaluation.ipynb Model eval
Components 16
Data pipeline
Raw hotel bookings, staged datasets, and notebook-driven preparation.
- Raw bookings · Source hotel booking records.
data/hotel_bookings.csv - Cleaned data · Audited and deduplicated booking table.
data/hotel_bookings_clean.csv - EDA data · Analysis-ready extract for exploration.
data/hotel_bookings_eda.csv - Feature data · Model-ready engineered booking dataset.
data/hotel_bookings_feature_engineered.csv - Data audit · Audit, cleaning, and dataset validation stage.
notebooks/01_data_audit.ipynb - EDA · Exploration and analysis stage.
notebooks/02_eda.ipynb - Feature eng · Feature creation and transformation stage.
notebooks/03_feature_eng.ipynb
Shared core
Feature definitions reused by training, evaluation, and the app.
- Features · Canonical feature-engineering logic shared across pipeline and app.
src/features.py
Offline modeling
Training, evaluation, and model bundle creation.
- Model eval · Model selection, thresholding, and evaluation stage.
notebooks/04_modeling_evaluation.ipynb - Train script · Training entrypoint for building the model artifact.
train_model.py - Rebuild script · Utility for regenerating the model bundle.
rebuild_model.py - Model bundle · Serialized inference pipeline used by the app.
Decision app
Streamlit scoring and explanation interface.
- Streamlit app · Decision-support interface for predictions, explanations, and batch scoring.
app/streamlit_app.py
SQL analytics
Standalone relational analysis subsystem.
- SQL analysis · SQLite analytical queries and revenue calculations.
Database/hotel_revenue.sql - SQLite DB · Standalone relational analysis database.
Database/hotel_revenue.db
Verification
Guardrails around feature consistency.
- Feature tests · Regression checks for feature consistency and encoding behavior.
tests/test_features.py
Connections 17
- Raw bookings → Data audit: inspect · Audit notebook starts from the raw CSV.
- Data audit → Cleaned data: produce · Cleaning stage writes the audited dataset.
- Cleaned data → EDA: analyze · EDA consumes the cleaned dataset.
- EDA → EDA data: stage · Exploration branch uses the EDA extract.
- EDA data → Feature eng: transform · Feature engineering starts from analysis data.
- Feature eng → Feature data: emit · Notebook produces the model-ready dataset.
- Feature data → Model eval: train · Model evaluation runs on engineered features.
- Features → Data audit: shared logic · Shared feature definitions constrain upstream schema handling.
- Features → Feature eng: shared logic · Notebook uses the canonical feature transformations.
- Features → Model eval: shared logic · Modeling uses the same feature contract.
- Features → Streamlit app: shared logic · App applies the same transformations at inference time.
- Features → Feature tests: verify · Tests guard the shared feature boundary.
- Model eval → Model bundle: publish · Evaluation stage culminates in a serialized model artifact.
- Train script → Model bundle: build · Training script produces the reusable bundle.
- Rebuild script → Model bundle: recreate · Rebuild utility regenerates the artifact.
- Model bundle → Streamlit app: serve · The app consumes the trained inference pipeline.
- SQL analysis → SQLite DB: populate · SQL analysis is backed by the SQLite database.