Back to the portfolio

TIME SERIES / PHARMACEUTICAL SALES

Demand changes.
So does the horizon.

A planner deciding what to replenish next week needs a different forecast from someone purchasing for the next quarter. This pharmaceutical sales study asks what a strong model score can actually tell us about those two decisions.

PythonTensorFlowLSTMProphetARIMAStreamlitIQVIA

Explore sales history, seasonal patterns and 1–12-week projections. The supplied history ends in December 2023; projections begin in January 2024.

Weekly observations
313
Sales categories
8
Input window
26 weeks
Holdout weeks
58

01 / THE PLANNING QUESTION

One series.
Two decisions.

Imagine a planner reviewing next week's replenishment and a buyer committing to several months of purchases. Both need to anticipate sales, but they have different horizons and different opportunities to update their information. This is the motivating scenario for the study, not a client engagement.

The supplied dataset spans January 2018 to December 2023. The notebook explores eight sales categories, then models N02BE using 26 weeks of previous sales. Excess inventory and shortages motivate the question, but their costs are not measured here.

Observed sales are the prediction target. Without stock availability and unmet-order data, they should not be treated as a complete measure of demand.

02 / THE OBSERVED SALES

Before the model,
look at the series.

A single average cannot describe every week. The largest observation, 128,659.48 sales units on 6 April 2020, sits outside the recorded evaluation period. That is a reason to test across several historical windows before trusting one headline score. N02BE monthly average weekly sales peak in March–May across the six years, with an exceptional March 2020 monthly average. This pattern supports investigating spring purchasing needs; the data alone does not establish a clinical cause.

Observed sales Recorded evaluation period

Weekly sales units (source: Extended Units)

N02BE weekly observed sales, 2018 to 2023313 weekly observations. Shading marks 21 November 2022 to 25 December 2023, the 58 recorded evaluation weeks. Use the week slider or data table to inspect exact values.0k50k100k201820192020202120222023
21 Nov 202252,305.78 unitsEvaluation week

Move across the chart or use the slider. Arrow keys step one week; Home and End jump to the first and last observations.

The series ranges from 47,527.89 to 128,659.48 weekly sales units. Shading marks the 58 evaluation targets from 21 November 2022 to 25 December 2023. This is observed sales history, not a forecast or proof of a clinical cause.

Explore all 313 weekly observations
Source: supplied iqvia_pharma_sales.csv. Dates and N02BE values are preserved; provenance is unverified.
WeekSales unitsEvaluation target
2018-01-0152,374.73No
2018-01-0857,653.58No
2018-01-1565,380.04No
2018-01-2266,801.53No
2018-01-2966,841.41No
2018-02-0574,106.01No
2018-02-1268,311.13No
2018-02-1969,055.46No
2018-02-2673,169.11No
2018-03-0576,668.37No
2018-03-1279,071.88No
2018-03-1979,241.01No
2018-03-2682,116.26No
2018-04-0278,902.79No
2018-04-0986,993.72No
2018-04-1683,542.69No
2018-04-2387,157.44No
2018-04-3085,238.00No
2018-05-0785,454.09No
2018-05-1485,423.05No
2018-05-2184,522.67No
2018-05-2884,241.27No
2018-06-0485,058.02No
2018-06-1180,795.98No
2018-06-1880,757.26No
2018-06-2577,039.74No
2018-07-0279,421.38No
2018-07-0971,914.65No
2018-07-1676,630.35No
2018-07-2369,711.99No
2018-07-3063,969.52No
2018-08-0666,130.09No
2018-08-1361,972.53No
2018-08-2064,119.29No
2018-08-2758,272.19No
2018-09-0357,093.93No
2018-09-1051,633.58No
2018-09-1754,056.31No
2018-09-2447,527.89No
2018-10-0148,737.58No
2018-10-0854,197.80No
2018-10-1553,674.75No
2018-10-2252,358.60No
2018-10-2948,522.80No
2018-11-0551,130.81No
2018-11-1251,640.33No
2018-11-1949,178.69No
2018-11-2657,178.49No
2018-12-0356,588.08No
2018-12-1054,937.72No
2018-12-1757,082.60No
2018-12-2452,177.16No
2018-12-3147,722.02No
2019-01-0756,080.48No
2019-01-1462,524.36No
2019-01-2163,726.25No
2019-01-2867,747.45No
2019-02-0475,410.42No
2019-02-1174,373.39No
2019-02-1873,130.25No
2019-02-2578,113.45No
2019-03-0482,132.33No
2019-03-1182,522.38No
2019-03-1881,701.71No
2019-03-2581,119.28No
2019-04-0185,830.24No
2019-04-0885,898.33No
2019-04-1587,893.85No
2019-04-2287,604.81No
2019-04-2988,874.30No
2019-05-0684,535.02No
2019-05-1389,158.57No
2019-05-2085,571.74No
2019-05-2789,782.56No
2019-06-0381,329.19No
2019-06-1086,576.06No
2019-06-1781,012.17No
2019-06-2477,125.95No
2019-07-0175,820.56No
2019-07-0874,385.99No
2019-07-1574,417.58No
2019-07-2272,656.40No
2019-07-2967,660.08No
2019-08-0567,073.11No
2019-08-1270,849.26No
2019-08-1967,766.24No
2019-08-2662,422.26No
2019-09-0259,587.24No
2019-09-0958,181.80No
2019-09-1658,045.54No
2019-09-2352,389.68No
2019-09-3053,377.78No
2019-10-0748,755.93No
2019-10-1453,694.05No
2019-10-2154,000.60No
2019-10-2850,864.56No
2019-11-0456,524.70No
2019-11-1149,420.26No
2019-11-1849,426.42No
2019-11-2554,836.02No
2019-12-0258,149.84No
2019-12-0961,175.65No
2019-12-1656,943.31No
2019-12-2355,561.76No
2019-12-3054,174.55No
2020-01-0657,436.02No
2020-01-1368,030.51No
2020-01-2069,510.42No
2020-01-2765,669.67No
2020-02-0375,985.35No
2020-02-1077,831.56No
2020-02-1774,501.64No
2020-02-2479,195.19No
2020-03-02117,285.67No
2020-03-09119,118.65No
2020-03-16119,159.79No
2020-03-23120,773.48No
2020-03-30124,140.11No
2020-04-06128,659.48No
2020-04-13127,935.43No
2020-04-2062,109.00No
2020-04-2765,286.67No
2020-05-0455,516.32No
2020-05-1165,977.77No
2020-05-1857,805.87No
2020-05-2560,893.19No
2020-06-0158,096.00No
2020-06-0856,706.46No
2020-06-1562,227.62No
2020-06-2256,680.11No
2020-06-2957,573.11No
2020-07-0670,494.99No
2020-07-1370,055.63No
2020-07-2067,081.42No
2020-07-2761,505.48No
2020-08-0365,680.78No
2020-08-1059,781.47No
2020-08-1755,082.32No
2020-08-2456,338.49No
2020-08-3159,848.63No
2020-09-0756,579.47No
2020-09-1451,997.01No
2020-09-2150,802.61No
2020-09-2849,878.46No
2020-10-0555,517.61No
2020-10-1250,408.69No
2020-10-1950,201.26No
2020-10-2651,709.48No
2020-11-0249,725.78No
2020-11-0948,765.55No
2020-11-1649,539.07No
2020-11-2350,702.14No
2020-11-3051,834.70No
2020-12-0755,121.95No
2020-12-1454,728.05No
2020-12-2158,128.54No
2020-12-2850,716.39No
2021-01-0462,062.91No
2021-01-1164,757.76No
2021-01-1874,813.30No
2021-01-2575,599.57No
2021-02-0179,694.65No
2021-02-0871,608.77No
2021-02-1587,286.20No
2021-02-2283,568.33No
2021-03-0189,067.38No
2021-03-0885,336.39No
2021-03-1591,633.10No
2021-03-2288,849.92No
2021-03-2991,474.03No
2021-04-0599,517.20No
2021-04-1294,869.79No
2021-04-1996,693.85No
2021-04-2698,899.90No
2021-05-0398,073.75No
2021-05-1097,043.49No
2021-05-1797,233.11No
2021-05-24102,036.23No
2021-05-3194,515.99No
2021-06-0787,108.13No
2021-06-1488,080.01No
2021-06-2186,725.08No
2021-06-2885,266.62No
2021-07-0581,970.11No
2021-07-1275,244.74No
2021-07-1980,640.77No
2021-07-2671,081.80No
2021-08-0272,822.66No
2021-08-0967,846.12No
2021-08-1667,581.73No
2021-08-2366,582.04No
2021-08-3064,601.22No
2021-09-0663,030.50No
2021-09-1364,532.36No
2021-09-2059,904.20No
2021-09-2756,711.45No
2021-10-0458,842.38No
2021-10-1158,571.73No
2021-10-1851,465.08No
2021-10-2555,982.78No
2021-11-0156,149.14No
2021-11-0853,624.58No
2021-11-1558,523.15No
2021-11-2255,105.01No
2021-11-2956,762.12No
2021-12-0657,114.82No
2021-12-1358,991.90No
2021-12-2057,582.59No
2021-12-2750,936.20No
2022-01-0362,664.64No
2022-01-1063,919.58No
2022-01-1765,651.01No
2022-01-2464,720.31No
2022-01-3170,995.98No
2022-02-0771,381.13No
2022-02-1481,515.87No
2022-02-2181,947.93No
2022-02-2879,431.13No
2022-03-0789,223.73No
2022-03-1487,580.64No
2022-03-2185,666.31No
2022-03-2881,227.96No
2022-04-0495,237.74No
2022-04-1186,310.88No
2022-04-1886,314.00No
2022-04-2593,894.87No
2022-05-0297,859.54No
2022-05-0994,931.14No
2022-05-1692,368.16No
2022-05-2391,827.26No
2022-05-3091,647.03No
2022-06-0690,283.44No
2022-06-1387,672.23No
2022-06-2085,666.16No
2022-06-2783,509.15No
2022-07-0479,793.19No
2022-07-1179,072.92No
2022-07-1873,203.02No
2022-07-2575,326.05No
2022-08-0170,755.78No
2022-08-0868,261.57No
2022-08-1569,545.96No
2022-08-2270,701.58No
2022-08-2967,432.76No
2022-09-0558,886.50No
2022-09-1258,717.98No
2022-09-1962,342.82No
2022-09-2655,839.60No
2022-10-0356,741.72No
2022-10-1057,925.93No
2022-10-1753,215.23No
2022-10-2455,711.89No
2022-10-3151,740.01No
2022-11-0753,858.12No
2022-11-1456,748.59No
2022-11-2152,305.78Yes
2022-11-2858,691.15Yes
2022-12-0558,632.90Yes
2022-12-1261,563.64Yes
2022-12-1962,283.27Yes
2022-12-2659,503.64Yes
2023-01-0259,847.80Yes
2023-01-0966,308.69Yes
2023-01-1669,945.92Yes
2023-01-2373,299.04Yes
2023-01-3074,232.94Yes
2023-02-0676,471.40Yes
2023-02-1376,710.91Yes
2023-02-2078,982.19Yes
2023-02-2779,071.90Yes
2023-03-0689,467.58Yes
2023-03-1383,240.58Yes
2023-03-2086,334.26Yes
2023-03-2787,681.37Yes
2023-04-0393,198.51Yes
2023-04-1090,963.82Yes
2023-04-1795,799.49Yes
2023-04-2491,088.89Yes
2023-05-0193,810.70Yes
2023-05-0890,722.01Yes
2023-05-1598,337.76Yes
2023-05-2288,769.91Yes
2023-05-2991,892.29Yes
2023-06-0591,628.36Yes
2023-06-1289,682.00Yes
2023-06-1986,514.97Yes
2023-06-2684,920.49Yes
2023-07-0383,486.74Yes
2023-07-1080,948.31Yes
2023-07-1781,800.32Yes
2023-07-2482,949.39Yes
2023-07-3173,304.72Yes
2023-08-0768,899.72Yes
2023-08-1470,137.47Yes
2023-08-2175,154.69Yes
2023-08-2864,049.51Yes
2023-09-0468,683.96Yes
2023-09-1167,028.99Yes
2023-09-1859,470.75Yes
2023-09-2561,104.41Yes
2023-10-0262,792.95Yes
2023-10-0956,503.57Yes
2023-10-1656,320.13Yes
2023-10-2354,918.32Yes
2023-10-3053,640.85Yes
2023-11-0654,777.46Yes
2023-11-1353,666.74Yes
2023-11-2057,734.19Yes
2023-11-2756,532.26Yes
2023-12-0460,418.94Yes
2023-12-1157,045.99Yes
2023-12-1863,732.51Yes
2023-12-2559,133.81Yes

03 / THE FORECASTING APPROACH

Twenty-six weeks in.
One prediction out.

  1. Explore weekly sales. Inspect trends, category correlations and seasonal patterns.
  2. Prepare sequences. All 313 observations remain in the modeling series. The 26-week window produces 229 pre-test sequences and 58 holdout targets. A chronological split reserves 35 pre-test sequences for validation; the scaler is fitted on the initial fitting observations.
  3. Fit a recurrent model. Two LSTM layers with 64 and 32 units feed dense layers with dropout. Validation selects seven training epochs, then the evaluation model is refitted on the pre-test sequences.
  4. Compare at a shared origin. Recursive LSTM, Prophet, ARIMA(2,1,2), persistence and a 52-week seasonal-naive baseline predict the same Monday dates, without receiving holdout sales. A separate all-history LSTM powers the dashboard projections.

04 / THE RECORDED RESULTS

Same origin.
Different horizons.

Every benchmark starts on 14 November 2022 and forecasts without new observations. The first 12 weeks cover 21 November 2022 to 6 February 2023. The full 58-week holdout ends on 25 December 2023.

BENCHMARK / SHARED CUTOFF

Compare like with like.

  1. Use only observations available before the holdout
  2. Forecast the same dates for all five models
  3. Inspect the first 12 weeks and the full holdout separately

The LSTM feeds its predictions back into its input window. Persistence repeats the last observation; seasonal naive repeats the preceding 52-week cycle. The comparison uses one forecast origin.

DASHBOARD / ALL-HISTORY MODEL

Explore what comes next.

  1. Load the saved all-history model and matching scaler
  2. Start with the last 26 observed N02BE weeks
  3. Generate recursive weekly point projections

Projections start on 1 January 2024 and extend to 18 March at the maximum horizon. No seasonal multipliers or confidence bands are added. These are historical exploratory sales projections.

Conceptual workflow diagrams. The benchmark evaluates pre-test models; its scores do not independently evaluate the dashboard's all-history refit.

Shared forecast origin: 14 November 2022. 21 November 2022 to 6 February 2023: 12 weekly targets.

Prophet1,639.275 units
LSTM recursive2,612.263 units
Seasonal naive (52 weeks)4,041.085 units
ARIMA(2,1,2)8,384.795 units
Persistence8,415.726 units

Lower is better. All five models forecast the same dates without holdout sales as inputs. These are recorded results at one origin, not evidence of statistical superiority. Source: notebook section 6, cell 29.

Prophet records the lowest MAE at both horizons: 1,639.275 Extended Units over 12 weeks and 3,551.134 over 58 weeks. The seasonal-naive baseline is close on full-holdout MAE at 3,617.887 and has a lower RMSE than Prophet. The recursive LSTM records MAE of 2,612.263 over 12 weeks and 6,299.634 over 58 weeks. Model choice depends on the horizon and error measure; this single origin does not establish a universally best model.

05 / FROM ANALYSIS TO ACTION

What this could mean
for planning.

Potential applications, not demonstrated outcomes. Use the observed spring pattern and benchmark results to design a replenishment pilot, with current planning practice as the comparison.

Inventory planners

Recommended action
Review N02BE purchasing and supplier capacity ahead of March–May, allowing for lead times. Confirm the seasonal pattern in recent data before changing orders.
Potential value
Earlier preparation for the observed high-sales period and possible supply constraints.
How to validate it
Compare stockout frequency, service levels, and average inventory against current practice. Use stock availability and supplier lead times to interpret the results.

Procurement and finance

Recommended action
Test Prophet, seasonal naive and recursive LSTM over several 12-week origins before using projections for purchasing or budgets.
Potential value
Better visibility into upcoming purchasing requirements.
How to validate it
Backtest cumulative 12-week errors and forecast bias, incorporating supplier lead times. Translate errors into purchasing costs only when cost data is available.

Category managers

Recommended action
Test whether lagged sales in related categories improve forecasts beyond N02BE history alone.
Potential value
Better coordination of category planning if the signals prove useful.
How to validate it
Compare models with and without those inputs on the same evaluation periods. Co-movement alone does not establish patient substitution or a causal relationship.

06 / INTERPRETING THE EVIDENCE

A useful signal.
A bounded claim.

One origin, limited generalisation. The comparison aligns dates and information available to each model, but covers one historical cutoff. ARIMA(2,1,2) is an untuned, nonseasonal baseline. Repeat the comparison across several origins before selecting a model.

Features versus inputs. N02BA and N02BE sales are strongly correlated (Pearson r ≈ 0.949). That suggests testing lagged cross-category signals; it does not show patient substitution. Calendar and category features are explored, but the LSTM receives only past N02BE sales.

Sales, uncertainty and value. Sales can be constrained by stock availability. Point projections do not quantify uncertainty, and the study does not measure inventory savings, service-level gains or shortage costs.

07 / WHAT I RECOMMEND

Match the evidence
to the decision.

  1. Prepare for the observed spring pattern. Review purchasing schedules and supplier capacity before March–May. Check recent sales and procurement lead times before setting a seasonal buffer.
  2. Choose a model for the planning horizon. Extend the matched-origin comparison to rolling 1-, 4- and 12-week evaluations. Keep Prophet, seasonal naive and LSTM as candidates; assess bias, underprediction and overprediction as well as average error.
  3. Measure value in a replenishment pilot. Combine forecasts with on-hand inventory, expiry dates, service targets, lead times, and shortage and holding costs. Validate prediction interval coverage, then compare stockout days, expiry waste and inventory costs with current practice.

08 / EXPLORE THE DASHBOARD

Inspect the history.
Try the horizon.

The Streamlit dashboard connects eight-category sales charts, an N02BE monthly heatmap, forecast controls and the recorded benchmark tables. Choose 1–12 weeks, inspect the forecast boundary, and download the projected values as CSV.

It loads a saved all-history TensorFlow model and matching scaler. No API key or retraining is needed. The displayed projections begin after the final observation in December 2023, so they should not be read as forecasts for today.

Open live dashboard

A forecast is useful only for the decision it was evaluated to support. The same model can produce different errors across planning horizons. Matching the forecast origin makes the comparison interpretable; repeated evaluation and operational data are the next steps toward a purchasing decision.

Explore other projects