Livedocs
Forecasting
Demand Forecasting
Time series forecasting using Facebook's Prophet library on ride booking data. It covers data exploration, and detailed analysis of daily ride demand, seasonality, and trend. The notebook provides a 60-day forecast, including confidence intervals and breaks down the forecast into various components. It highlights the business value of accurate forecasts for resource planning and strategic decision-making, offering clear, actionable insights for operations.
Tip: Try `uv pip` for āš”ļø installs:
!uv pip install
empty line
Collecting prophet
empty line
Downloading prophet-1.1.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.5 kB)
Requirement already satisfied: plotly in ./data/.venv/lib/python3.12/site-packages (6.1.1)
empty line
Collecting cmdstanpy>=1.0.4 (from prophet)
Downloading cmdstanpy-1.2.5-py3-none-any.whl.metadata (4.0 kB)
empty line
Requirement already satisfied: numpy>=1.15.4 in ./data/.venv/lib/python3.12/site-packages (from prophet) (2.2.4)
Requirement already satisfied: matplotlib>=2.0.0 in ./data/.venv/lib/python3.12/site-packages (from prophet) (3.10.1)
Requirement already satisfied: pandas>=1.0.4 in ./data/.venv/lib/python3.12/site-packages (from prophet) (2.3.2)
empty line
Collecting holidays<1,>=0.25 (from prophet)
Downloading holidays-0.81-py3-none-any.whl.metadata (49 kB)
Requirement already satisfied: tqdm>=4.36.1 in ./data/.venv/lib/python3.12/site-packages (from prophet) (4.67.1)
empty line
Collecting importlib_resources (from prophet)
Downloading importlib_resources-6.5.2-py3-none-any.whl.metadata (3.9 kB)
empty line
Requirement already satisfied: python-dateutil in ./data/.venv/lib/python3.12/site-packages (from holidays<1,>=0.25->prophet) (2.9.0.post0)
Requirement already satisfied: narwhals>=1.15.1 in ./data/.venv/lib/python3.12/site-packages (from plotly) (2.5.0)
Requirement already satisfied: packaging in ./data/.venv/lib/python3.12/site-packages (from plotly) (25.0)
Collecting stanio<2.0.0,>=0.4.0 (from cmdstanpy>=1.0.4->prophet)
Downloading stanio-0.5.1-py3-none-any.whl.metadata (1.6 kB)
empty line
Requirement already satisfied: contourpy>=1.0.1 in ./data/.venv/lib/python3.12/site-packages (from matplotlib>=2.0.0->prophet) (1.3.3)
Requirement already satisfied: cycler>=0.10 in ./data/.venv/lib/python3.12/site-packages (from matplotlib>=2.0.0->prophet) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in ./data/.venv/lib/python3.12/site-packages (from matplotlib>=2.0.0->prophet) (4.60.0)
Requirement already satisfied: kiwisolver>=1.3.1 in ./data/.venv/lib/python3.12/site-packages (from matplotlib>=2.0.0->prophet) (1.4.9)
Requirement already satisfied: pillow>=8 in ./data/.venv/lib/python3.12/site-packages (from matplotlib>=2.0.0->prophet) (11.3.0)
Requirement already satisfied: pyparsing>=2.3.1 in ./data/.venv/lib/python3.12/site-packages (from matplotlib>=2.0.0->prophet) (3.2.5)
empty line
Requirement already satisfied: pytz>=2020.1 in ./data/.venv/lib/python3.12/site-packages (from pandas>=1.0.4->prophet) (2025.2)
Requirement already satisfied: tzdata>=2022.7 in ./data/.venv/lib/python3.12/site-packages (from pandas>=1.0.4->prophet) (2025.2)
empty line
Requirement already satisfied: six>=1.5 in ./data/.venv/lib/python3.12/site-packages (from python-dateutil->holidays<1,>=0.25->prophet) (1.17.0)
empty line
Downloading prophet-1.1.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/14.4 MB ? eta -:--:--
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.4/14.4 MB 29.8 MB/s 0:00:00
Downloading holidays-0.81-py3-none-any.whl (1.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/1.3 MB ? eta -:--:--
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 40.7 MB/s 0:00:00
Downloading cmdstanpy-1.2.5-py3-none-any.whl (94 kB)
Downloading stanio-0.5.1-py3-none-any.whl (8.1 kB)
empty line
Downloading importlib_resources-6.5.2-py3-none-any.whl (37 kB)
empty line
Installing collected packages: stanio, importlib_resources, holidays, cmdstanpy, prophet
empty line
empty line
Successfully installed cmdstanpy-1.2.5 holidays-0.81 importlib_resources-6.5.2 prophet-1.1.7 stanio-0.5.1
empty line
āœ… Libraries installed and imported successfully!
ncr_ride_bookin...
DateTimeBooking IDBooking StatusCustomer IDVehicle TypePickup LocationDrop LocationAvg VTATAvg CTATCancelled Rides by CustomerReason for cancelling by CustomerCancelled Rides by DriverDriver Cancellation ReasonIncomplete RidesIncomplete Rides ReasonBooking ValueRide DistanceDriver RatingsCustomer RatingPayment Method
2024-03-23
12:29:38
"CNR5884300"
No Driver Found
"CID1982111"
eBike
Palam Vihar
Jhilmil
null
null
null
null
null
null
null
null
null
null
null
null
null
2024-11-29
18:01:39
"CNR1326809"
Incomplete
"CID4604802"
Go Sedan
Shastri Nagar
Gurgaon Sector 56
4.9
14.0
null
null
null
null
1
Vehicle Breakdown
237
5.73
null
null
UPI
2024-08-23
08:56:10
"CNR8494506"
Completed
"CID9202816"
Auto
Khandsa
Malviya Nagar
13.4
25.8
null
null
null
null
null
null
627
13.58
4.9
4.9
Debit Card
2024-10-21
17:17:25
"CNR8906825"
Completed
"CID2610914"
Premier Sedan
Central Secretariat
Inderlok
13.1
28.5
null
null
null
null
null
null
416
34.02
4.6
5.0
UPI
2024-09-16
22:08:00
"CNR1950162"
Completed
"CID9933542"
Bike
Ghitorni Village
Khan Market
5.3
19.6
null
null
null
null
null
null
737
48.21
4.1
4.3
UPI
2024-02-06
09:44:56
"CNR4096693"
Completed
"CID4670564"
Auto
AIIMS
Narsinghpur
5.1
18.1
null
null
null
null
null
null
316
4.85
4.1
4.6
UPI
2024-06-17
15:45:58
"CNR2002539"
Completed
"CID6800553"
Go Mini
Vaishali
Punjabi Bagh
7.1
20.4
null
null
null
null
null
null
640
41.24
4.0
4.1
UPI
2024-03-19
17:37:37
"CNR6568000"
Completed
"CID8610436"
Auto
Mayur Vihar
Cyber Hub
12.1
16.5
null
null
null
null
null
null
136
6.56
4.4
4.2
UPI
2024-09-14
12:49:09
"CNR4510807"
No Driver Found
"CID7873618"
Go Sedan
Noida Sector 62
Noida Sector 18
null
null
null
null
null
null
null
null
null
null
null
null
null
2024-12-16
19:06:48
"CNR7721892"
Incomplete
"CID5214275"
Auto
Rohini
Adarsh Nagar
6.1
26.0
null
null
null
null
1
Other Issue
135
10.36
null
null
Cash
10 Rows
ncr_ride_bookin...
total_ridesearliest_datelatest_dateunique_datesunique_statuses
150000
2024-01-01
2024-12-30
365
5
1 Rows
ncr_ride_bookin...
Booking Statuscountpercentage
Completed
93000
62
Cancelled by Driver
27000
18
No Driver Found
10500
7
Cancelled by Customer
10500
7
Incomplete
9000
6
5 Rows
ncr_ride_bookin...
dsy
2024-01-01
414
2024-01-02
389
2024-01-03
384
2024-01-04
414
2024-01-05
416
2024-01-06
409
2024-01-07
437
2024-01-08
387
2024-01-09
434
2024-01-10
407
365 Rows
šŸ“Š Time Series Data Summary: Date range: 2024-01-01 00:00:00 to 2024-12-30 00:00:00 Total days: 365 Average daily rides: 411.0 Min daily rides: 355 Max daily rides: 462 Standard deviation: 20.6 šŸ” First 5 days: ds y 0 2024-01-01 414 1 2024-01-02 389 2 2024-01-03 384 3 2024-01-04 414 4 2024-01-05 416
Output Image image/png - 3505842c-71d7-4666-89f9-3be9cc6b4827
šŸ“ˆ Trend Analysis: Decreasing trend of -0.01 rides per day šŸ“Š Data Quality: R² = 0.003 (closer to 1.0 means stronger trend)

Key Observations from Historical Data

From our analysis of 2024 ride booking data:

  • Stable Demand: Daily rides range from 355 to 462, with an average of 411 rides per day
  • Minimal Overall Trend: Very slight decreasing trend (-0.01 rides/day) with R² = 0.003, indicating the data is relatively stable without strong directional movement
  • Good for Forecasting: This stability suggests Prophet can focus on detecting seasonal patterns rather than dealing with dramatic trend changes

What Prophet Will Help Us Discover:

  1. Weekly Seasonality: Are there patterns between weekdays and weekends?
  2. Monthly/Yearly Patterns: Do certain times of year show higher demand?
  3. Future Predictions: What should we expect for the next 60 days?
  4. Uncertainty Estimates: How confident can we be in these predictions?

Now let's build our Prophet model!

šŸ¤– Initializing Prophet model... šŸ“Š Training the model on 2024 data...
08:48:27 - cmdstanpy - INFO - Chain [1] start processing
08:48:27 - cmdstanpy - INFO - Chain [1] done processing
āœ… Model training completed! šŸ“Š Model trained on 365 days of data šŸ—ŗļø Date range: 2024-01-01 to 2024-12-30
šŸ”® Generating predictions for the next 60 days... šŸ“… Prediction period: 2025-02-28 (60 days ahead) šŸ“ˆ Last 10 days of predictions: ds yhat yhat_lower yhat_upper trend weekly yearly 415 2025-02-19 408.9 366.7 448.7 408.9 -0.0 -0.0 416 2025-02-20 408.7 366.0 448.5 408.9 -0.1 0.0 417 2025-02-21 408.9 368.5 449.3 408.8 0.0 0.0 418 2025-02-22 408.9 370.3 448.0 408.8 0.0 0.0 419 2025-02-23 408.9 363.9 445.6 408.8 0.0 0.0 420 2025-02-24 408.9 369.2 449.0 408.8 0.0 0.0 421 2025-02-25 408.9 369.0 448.8 408.8 0.0 0.0 422 2025-02-26 408.8 371.4 448.7 408.8 -0.0 0.1 423 2025-02-27 408.7 369.5 448.7 408.8 -0.1 0.1 424 2025-02-28 408.9 369.9 447.4 408.8 0.0 0.1 šŸ“‚ Future Prediction Summary (Next 60 days): Average daily rides predicted: 409.0 Range: 408.7 to 409.3 95% Confidence interval: 368.9 to 448.9
Output Image image/png - 38148e38-3adc-4725-bf71-91860cc92bf7
āœ… Comprehensive forecast visualization created!

How Prophet Breaks Down the Forecast

Prophet decomposes our ride booking predictions into several key components:

1. Trend (Green line in bottom chart)

  • The underlying direction of the data over time
  • Shows whether demand is generally increasing, decreasing, or stable
  • Our data shows a very stable trend around 409 rides/day

2. Weekly Seasonality (Orange line)

  • Day-of-week patterns - weekdays vs. weekends
  • Captures whether certain days consistently have higher or lower demand
  • Values around 0 suggest minimal weekly variation in our data

3. Yearly Seasonality (Purple line)

  • Seasonal business cycles throughout the year
  • Accounts for holidays, weather patterns, school schedules, etc.
  • Shows how ride demand varies by time of year

4. Confidence Intervals (Red shaded area)

  • The uncertainty range around our predictions
  • 95% confidence means we're 95% sure actual values will fall in this range
  • Wider intervals = more uncertainty, narrower = more confidence

Next, let's dive deeper into weekly patterns!

šŸ—… Weekly Seasonality Analysis ======================================== Monday: +0.0 effect | 409.3 total rides Tuesday: +0.0 effect | 409.2 total rides Wednesday: -0.0 effect | 409.2 total rides Thursday: -0.1 effect | 409.0 total rides Friday: +0.0 effect | 409.1 total rides Saturday: +0.0 effect | 409.1 total rides Sunday: +0.0 effect | 409.1 total rides šŸ“Š Interpretation: - Positive values = higher than average demand - Negative values = lower than average demand - Values close to 0 = minimal weekly variation šŸŽ… Yearly Seasonality Insights ======================================== Peak demand period: January 26 (+0.1 rides) Low demand period: January 01 (-0.4 rides) Seasonal variation range: 0.6 rides šŸŽ† Business Insights: - Relatively stable demand throughout the year - Consistent operational planning is appropriate - Less need for seasonal adjustments
Output Image image/png - 9fdda99e-961a-41f6-8428-617ce86f7247
āœ… Prophet forecasting demonstration completed! šŸŽ† Key takeaway: Very stable ride demand with minimal seasonality - excellent for business planning!
BokehDeprecationWarning: 'circle() method with size value' was deprecated in Bokeh 3.4.0 and will be removed, use 'scatter(size=...) instead' instead.
✨ Interactive Bokeh chart created! Features: šŸ” Zoom: Use mouse wheel or box zoom tool šŸ“± Pan: Click and drag šŸŽ›ļø Legend: Click to hide/show series šŸ”„ Reset: Click reset button to return to original view