Downloads · 30 days
0
Reut1/hotel-booking-price-predictor
hotel-booking-price-predictor is a machine learning model from Reut1. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as cc-by-4.0.
Author: Reut Assignment: 2 - Machine Learning Pipeline Video: - Link Colab Notebook: Link
Downloads · 30 days
0
Access
Public
Updated Dec 11, 2025
Repo size
783 MB
Likes
0
Public
Click a slice to open those files.
.pkl764 MB · 97%
From the Hugging Face model README
Author: Reut Assignment: #2 - Machine Learning Pipeline Video: - Link Colab Notebook: Link
Project Goal: To build a comprehensive machine learning pipeline that predicts daily room rates (Regression) and classifies bookings into pricing tiers (Classification), utilizing advanced feature engineering and clustering techniques.
This project follows a structured 8-part pipeline:
adr (Average Daily Rate).Before modeling, the raw dataset underwent a rigorous cleaning and analysis process to ensure data integrity and model stability.
agent and company columns by imputing with 0 (indicating direct bookings)..png)
%2520by%2520Month.png)
assigned_room_type feature showed a distinct price hierarchy; Room types 'G' and 'H' consistently command significantly higher rates than standard 'A' rooms.


Booking Behavior: The scatter plot of Lead Time vs. ADR reveals a slight negative trend, indicating that while early bookers often secure lower rates, the highest prices are frequently associated with last-minute "Spontaneous" bookings.

To establish a performance benchmark, I developed a baseline Linear Regression model. This section details the setup, training, and initial evaluation.
adr (Average Daily Rate) to estimate the nightly room price.market_segment, reserved_room_type) to make them interpretable for the linear model.random_state=42 to ensure reproducibility.I trained a standard LinearRegression model from Scikit-Learn. The model achieved moderate predictive power but highlighted the limitations of linear assumptions on this complex dataset.
| Metric | Value | Interpretation |
|---|---|---|
| MAE | $22.02 | On average, the prediction is off by ~$22. |
| RMSE | $29.91 | Penalizes larger errors more heavily. |
| R² Score | 0.65 | The model explains 65% of the variance in price. |
By analyzing the Linear Coefficients, I identified the primary drivers of price:
assigned_room_type_L had a strong negative coefficient (-$135), identifying a specific low-cost category or booking anomaly.distribution_channel_Undefined as a negative predictor highlighted the need for the robust data cleaning performed in earlier steps.Visual Analysis: The Actual vs. Predicted scatter plot showed that while the model captures the general trend, it struggles to predict extreme high-end prices (underestimation), suggesting the need for non-linear models (addressed in Part 5).
.png)
To significantly improve model performance, I moved beyond raw features and applied advanced Feature Engineering techniques. The highlight of this step was the creation of a meta-feature using Unsupervised Learning.
Before applying clustering algorithms, data preprocessing was essential to ensure valid results:
lead_time, total_of_special_requests, total_stay) while strictly excluding the target variable (adr) to prevent Data Leakage.sklearn.preprocessing.StandardScaler to normalize all behavioral features to a mean of 0 and variance of 1.I employed K-Means Clustering (sklearn.cluster.KMeans) to uncover hidden patterns in customer behavior. By setting k=4, the algorithm identified four distinct customer personas.
Cluster Interpretation:
.png)
sklearn.decomposition.PCA). The resulting scatter plot confirmed distinct separations between the groups.Cluster. This enriched the subsequent supervised models (Regression/Classification) with "behavioral context" they wouldn't have derived from raw features alone.Following the baseline evaluation, I aimed to improve prediction accuracy
total_stay and Cluster features) to isolate the impact of feature engineering.###Model Comparison Results The models were evaluated on the test set using Mean Absolute Error (MAE) and R-Squared (R2).
| Model | MAE (Error in $) | R2 Score | Performance |
|---|---|---|---|
| Linear Regression (Retrained) | 22.01 | 0.65 | Baseline |
| XGBoost | 11.84 | 0.87 | Strong |
| Random Forest | 9.08 | 0.89 | Best |
| ###Discussion and Feature Importance | |||
| The Random Forest model achieved a dramatic performance boost, reducing the Mean Absolute Error by over 50% compared to the linear baseline. | |||
![]() | |||
![]() |
Reasons for Improvement:
Cluster feature provided valuable business insights during EDA, it did not appear in the top 10 predictors for the Random Forest model. This is likely due to information redundancy, as the model could extract the necessary patterns directly from the raw features (Lead Time, Guest Count) that made up the clusters.In this phase, I reframed the business problem from predicting the exact daily rate (Regression) to classifying bookings into pricing tiers (Classification). This facilitates strategic decision-making regarding market segmentation.
Objective: Convert the continuous target adr into discrete classes.
Chosen Strategy: Quantile Binning I discretized the target variable into 3 equal-sized classes:
Rationale: I selected Quantile Binning over arbitrary thresholds to ensure a perfectly balanced dataset. This prevents the model from becoming biased toward a majority class (a common issue with manual cutoffs) and ensures equal learning opportunity for all price tiers.
I performed a rigorous sanity check before training:
Metric Strategy:In this final modeling phase, I trained and evaluated three distinct classifiers to predict the price tier (0, 1, 2).
While Accuracy is a valid metric due to our perfectly balanced dataset (achieved in Part 7), I introduced a critical business constraint: Minimizing False Positives for the 'High' class.
I benchmarked a linear classifier against non-linear tree-based models. The results clearly favored the ensemble approach:
| Model | Overall Accuracy | 'High' Class Precision | Interpretation |
|---|---|---|---|
| Logistic Regression | 60% | 0.66 | Underperformed; failed to capture complex pricing rules. |
| Decision Tree | 84% | 0.87 | Strong improvement; learned non-linear decision boundaries. |
| Random Forest | 86% | 0.89 | Winner |
Random Forest Classifier is the chosen model. It achieved the highest overall accuracy (86%) and, crucially, a Precision of 0.89 for premium bookings. This means when the model predicts a "High" price tag, it is correct 89% of the time, significantly reducing the risk of driving customers away with inflated prices.
This project highlights the importance of a holistic approach: clean data, thoughtful feature engineering (Clustering), and selecting the right model for the task. The combination of visual exploration and advanced predictive techniques led to a robust pricing engine capable of adapting to seasonality and customer types with high accuracy.
Load the trained models using Python:
import joblib
import pandas as pd
# 1. Load Regression Model (Predicts exact price)
reg_model = joblib.load('hotel_price_prediction_model.pkl')
# 2. Load Classification Model (Predicts Price Tier 0-2)
clf_model = joblib.load('hotel_price_classifier_model.pkl')