Tuesday, May 6, 2025

Supply Chain and Inventory Management – Demand Forecasting

 


Notes:

  • Problem Solved: Predicts future product demand using historical sales data, aiding in inventory planning.

  • Benefits: Helps businesses plan inventory levels based on forecasted demand, optimizing stock levels.

  • Adoption: Integrate this forecasting model with sales data to generate periodic demand forecasts.

Python Code:


import pandas as pd

from sklearn.linear_model import LinearRegression

import numpy as np


class DemandForecaster:

    def __init__(self, sales_data):

        self.sales_data = pd.DataFrame(sales_data)

        self.model = LinearRegression()


    def train_model(self):

        X = np.array(self.sales_data['Month']).reshape(-1, 1)

        y = self.sales_data['Sales']

        self.model.fit(X, y)


    def forecast_demand(self, months_ahead):

        future_months = np.array(range(len(self.sales_data) + 1, len(self.sales_data) + 1 + months_ahead)).reshape(-1, 1)

        forecast = self.model.predict(future_months)

        return forecast


# Sample sales data

sales_data = [

    {'Month': 1, 'Sales': 200},

    {'Month': 2, 'Sales': 220},

    {'Month': 3, 'Sales': 240},

    {'Month': 4, 'Sales': 260},

    {'Month': 5, 'Sales': 280},

]


# Initialize forecaster

forecaster = DemandForecaster(sales_data)


# Train model

forecaster.train_model()


# Forecast next 3 months

forecast = forecaster.forecast_demand(3)

print(f"Forecasted demand for next 3 months: {forecast}")


No comments:

Post a Comment

IoT (Internet of Things) Automation - Smart Energy Usage Tracker

  Notes: Problem Solved: Logs and analyzes power usage from smart meters. Customization Benefits: Track per-device energy and set ale...