Why Product Demand Prediction Issues
Predicting demand helps companies in a number of methods:
- Stock Administration: Keep away from overstocking or stockouts, decreasing storage prices and misplaced gross sales.
- Useful resource Allocation: Optimize manufacturing schedules and workforce planning.
- Strategic Planning: Make knowledgeable choices about market growth and promotional actions.
The Position of Machine Studying in Demand Prediction
Machine studying (ML) algorithms can uncover patterns and relationships in historic information that conventional strategies may miss. By studying from previous information, these algorithms could make extra correct and dynamic predictions.
Introduction
As the vacation season approaches, corporations are eager to optimize their pricing methods to maximise gross sales and outpace rivals. On this case research, we’ll discover how a product firm can leverage machine studying to foretell demand primarily based on completely different value segments. The objective is to seek out the optimum low cost value that makes the product a compelling deal in comparison with rivals.
Goal
The corporate goals to foretell product demand at numerous value factors to find out the perfect low cost technique for the upcoming vacation season. By analyzing previous gross sales information in relation to cost modifications, we will construct a predictive mannequin to forecast future demand.
Dataset
The supplied dataset contains historic gross sales information with the next options:
- the product id;
- retailer id;
- whole value at which product was bought;
- base value at which product was bought;
- Items bought (amount demanded);
We begin by loading and making ready the dataset.
import pandas as pd
import numpy as np
import plotly.categorical as px
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressorinformation = pd.read_csv("https://uncooked.githubusercontent.com/amankharwal/Web site-data/grasp/demand.csv")
information.head()
ID 0
Retailer ID 0
Complete Value 1
Base Value 0
Items Offered 0
dtype: int64
Knowledge Cleansing
Subsequent, we test for and deal with any lacking values within the dataset. On this case, we’ve got one lacking worth within the ‘Complete Value’ column, which we’ll take away.
# Verify for lacking values
print(information.isnull().sum())# Take away rows with lacking values
information = information.dropna()
Knowledge Visualization
Let’s analyze the connection between value and demand utilizing a scatter plot. We are going to create a sophisticated and interactive scatter plot utilizing Plotly.
# Scatter plot to visualise the connection between Items Offered and Complete Value
fig = px.scatter(information, x="Items Offered", y="Complete Value",
dimension='Items Offered',
title="Relationship between Items Offered and Complete Value",
labels={"Items Offered": "Items Offered", "Complete Value": "Complete Value"},
hover_name="Retailer ID")
# Save plot
plt.savefig('1.png')
# Present plot
fig.present()
We will see that many of the information factors present the gross sales of the product is rising as the worth is reducing with some exceptions. Now let’s take a look on the correlation between the options of the dataset:
# Calculate and print the correlation matrix
corr_matrix = information.corr()
print(corr_matrix)# Visualize the correlation matrix
plt.determine(figsize=(10, 8))
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', linewidths=0.5)
plt.title('Correlation Matrix')
plt.savefig('correlation_matrix.png')
plt.present()
Product Demand Prediction Mannequin Now let’s transfer to the duty of coaching a machine studying mannequin to foretell the demand for the product at completely different costs. I’ll select the Complete Value and the Base Value column because the options to coach the mannequin, and the Items Offered column as labels for the mannequin:
# Put together information
x = information[["Total Price", "Base Price"]]
y = information["Units Sold"]# Break up information into coaching and check units
xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2, random_state=42)
# Prepare Resolution Tree Regressor mannequin
mannequin = DecisionTreeRegressor(random_state=42)
mannequin.match(xtrain, ytrain)
# Outline options for prediction
options = np.array([[133.00, 140.00]])# Predict demand primarily based on options
predicted_demand = mannequin.predict(options)
print(f'Predicted demand: {predicted_demand}')
Abstract
So that is how one can prepare a machine studying mannequin for the duty of product demand prediction utilizing Python. Value is likely one of the main elements that have an effect on the demand for the product. If a product just isn’t a necessity, only some folks purchase the product even when the worth will increase. I hope you appreciated this text on product demand prediction with machine studying utilizing Python. Be at liberty to ask your priceless questions within the feedback part beneath.