Code
# 1️⃣ Load Data
import pandas as pd
= pd.read_csv('../data/raw/hotel_bookings.csv')
df
# Preprocess date columns
'reservation_status_date'] = pd.to_datetime(df['reservation_status_date']) df[
# 3️⃣ Plot Demand Over Time
import matplotlib.pyplot as plt
'reservation_status_date')['bookings'].plot(figsize=(12,6))
bookings_by_date.set_index('Total Bookings Over Time')
plt.title('Date')
plt.xlabel('Number of Bookings')
plt.ylabel( plt.show()
# 4️⃣ Prophet Model
from prophet import Prophet
# Prepare data for Prophet
= bookings_by_date.rename(columns={'reservation_status_date': 'ds', 'bookings': 'y'})
df_prophet
# Initialize model
= Prophet()
m
m.fit(df_prophet)
# Create future dataframe
= m.make_future_dataframe(periods=60) # Forecast 60 days ahead
future
# Forecast
= m.predict(future)
forecast
# Plot forecast
= m.plot(forecast) fig
20:13:18 - cmdstanpy - INFO - Chain [1] start processing
20:13:19 - cmdstanpy - INFO - Chain [1] done processing
# 5️⃣ XGBoost Model (Optional / Advanced)
# Feature engineering for ML model
'dayofweek'] = bookings_by_date['reservation_status_date'].dt.dayofweek
bookings_by_date['month'] = bookings_by_date['reservation_status_date'].dt.month
bookings_by_date['year'] = bookings_by_date['reservation_status_date'].dt.year
bookings_by_date[
# Define features and target
= ['dayofweek', 'month', 'year']
features = bookings_by_date[features]
X = bookings_by_date['bookings']
y
# Split data
from sklearn.model_selection import train_test_split
= train_test_split(X, y, test_size=0.2, shuffle=False)
X_train, X_test, y_train, y_test
# Train XGBoost model
from xgboost import XGBRegressor
= XGBRegressor()
model
model.fit(X_train, y_train)
# Predict
= model.predict(X_test)
y_pred
# Plot predictions
=(12,6))
plt.figure(figsize='Actual')
plt.plot(y_test.values, label='Predicted')
plt.plot(y_pred, label'XGBoost Demand Forecast - Test Set')
plt.title(
plt.legend() plt.show()