Skip to content

Repository files navigation

💊 PharmaCast

Predicting Demand. Protecting Patients. Optimising Inventory.

Python scikit-learn pandas matplotlib Status License

pharm

🎯 The Problem

One of the most common challenges in the pharmaceutical supply chain is inventory distortion — the imbalance between overstocking and understocking.

For a typical retail business, a stockout means a lost sale. In the pharmaceutical industry, the stakes are infinitely higher — it can mean a delay in life-saving treatment. This immense responsibility is why effective pharmacy inventory forecasting is not just a good business practice, but a critical component of patient safety.


The Solution

PharmaCast predicts medication demand to help pharmacies:

  • reduce stockouts
  • avoid overstocking
  • improve procurement decisions

pharm


Architecture

Raw Sales Data
      ↓
EDA & Decomposition
      ↓
Feature Engineering
      ↓
Model Training
      ↓
 Evaluation
      ↓
Inventory Insights

💡 Key Insights

  • Paracetamol drives 49.4% of total sales
  • Annual seasonality is strong
  • Weekly seasonality is negligible
  • Saturday is the busiest day
  • Linear Regression performed nearly as well as Random Forest

🛠️ Getting Started

1. Clone the repository

git clone https://github.com/anaboset/FUTURE_ML_01
cd FUTURE_ML_01

pip install -r requirements.txt

Place the dataset at FUTURE_ML_01/data/pharma-sales-data/salesdaily.csv

jupyter notebook pharma_sales_forecast.ipynb

Run all cells from top to bottom. Each chapter builds on the previous one.


📁 Project Structure

FUTURE_ML_01/
│
├── data/
│   └── pharma-sales-data/         # Place dataset here (not tracked by git)
│       └── salesdaily.csv
│
├── outputs/                       # Generated plots saved by the notebook
│   ├── 01_exploratory_overview.png
│   ├── 01b_drug_composition.png
│   ├── 02_decomposition_comparison.png
│   ├── 03_actual_vs_predicted.png
│   ├── 04_feature_importance.png
│   ├── 05_residual_analysis.png
│   ├── 06_prediction_confidence.png
│   └── 07_scorecard.png
│
├── pharma_sales_forecast.ipynb    # Full narrative analysis notebook
├── requirements.txt
├── .gitignore
└── README.md

📊 The Dataset

The model was trained on a pharmacy sales dataset obtained from Kaggle, containing historical transactional sales records from 2014–2019.

Getting the Data

The dataset is not included in this repository. To set it up locally:

Option 1 — Download manually

  1. Go to https://www.kaggle.com/datasets/milanzdravkovic/pharma-sales-data
  2. Click Download
  3. Extract and place salesdaily.csv at:
FUTURE_ML_01/data/pharma-sales-data/salesdaily.csv

The notebook reads the file from this path. No other configuration is needed.

Option 2 — Download via kagglehub

pip install kagglehub
import kagglehub
from kagglehub import KaggleDatasetAdapter

df = kagglehub.load_dataset(
    KaggleDatasetAdapter.PANDAS,
    "milanzdravkovic/pharma-sales-data",
    ""
)

A Kaggle account and configured API token are required for Option 2.
See Kaggle API setup for instructions.



⚠️ Limitations

  • Cannot predict external outbreaks/events
  • Requires historical sales data
  • Large unexplained spikes still affect accuracy
  • Retraining needed monthly

👤 Author's Note

If the forecast helps a single pharmacy avoid a stockout on a critical medication, the project has achieved its purpose.


Built by AI Engineer & pharmacy student

About

A narrative ML forecasting project that predicts pharmaceutical demand from 6 years of daily sales data, translating time-series analysis into concrete inventory and procurement decisions.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages