Leveraging Machine Learning for Efficiency in Supply Chain Management

Guest Blog Last Updated : 30 Jul, 2020
7 min read

Machine Learning For Supply Chain management

Business Case

Machine Learning and Supply Chain Management : Sample Historical Data exported from ERP to train the machine learning algorithm

Machine Learning in Supply Chain Management

 

I will explain each line of the code and then put the full code at the end of the article for reference. As mentioned earlier, I have oversimplified a few things here for us to understand the core concept, and in future series, I will build more real-life complex examples on it.

  1. Step 1

    First, we will import all the python modules which we will be using in our machine learning program. I will not go in detail about these libraries and modules here in this article, and you can find more details about these modules online.

    import pandas as pd
    from sklearn.tree import DecisionTreeRegressor # Import Decision Tree Algorithm
    from sklearn.preprocessing import StandardScaler
    from sklearn.svm import SVR #import for support vector regressor

    Pandas is a software library written in Python for data manipulation and analysis. It is very easy to read and write data in excel, CSV, and other file formats using Pandas, and work with time-series data.

    Scikit-learn is a free machine learning library for python. We will be predicting the defect percentage in the future supplier delivery using Decision Tree Learning and Support Vector Machine. We will import specifically these two modules from Scikit Learn for the same.

  2. Step 2

    Then, we will read the past data points in an excel file and save it to pandas dataframe SourceData. Similarly, we will read the data points of the delivery for which we want the algorithm to predict the delivery defect percentage.

    SourceData=pd.read_excel("Supplier Past Performance.xlsx") # Load the training data into Pandas DataFrameTestdata=pd.read_excel("Defect Predict.xlsx") # Load the test data
  3. Step 3

    SourceData_train_independent= SourceData.drop(["Defect Percent"], axis=1) # Drop depedent variable from training datasetSourceData_train_dependent=SourceData["Defect Percent"].copy() 
    # New dataframe with only independent variable value for training dataset
  4. Step 4

    sc_X = StandardScaler()
    
    X_train=sc_X.fit_transform(SourceData_train_independent.values) 
    # scale the independent training datasetvariablesX_test=sc_X.transform(Testdata.values) # scale the independent test datasety_train=SourceData_train_dependent # scaling is not required for dependent variable
  5. Step 5

    svm_reg = SVR(kernel="linear", C=1)
    svm_reg.fit(X_train, y_train) # fit and train the modelpredictions = svm_reg.predict(X_test)
    
    print("Defect percent prediction by Support Vector model for the order value of 95827 GBP with 851 pallets sent 55 days before delivery data is " ,round(predictions[0],2) , "%")

    Machine Learning and Supply Chain Management : Defect Percentage

  6. Step 6

    In the same way, we will feed the training dataset (independent and dependent variable value) to the Decision Tree model.

    tree_reg = DecisionTreeRegressor()
    tree_reg.fit(X_train, y_train) # fit and train the modeldecision_predictions = tree_reg.predict(X_test) # Predict the value of dependent variableprint("Defect percent prediction by Decision Tree model for the order value of 95827 GBP with 851 pallets sent 55 days before delivery data is " ,round(decision_predictions[0],2) , "%")

    Image for post

""" Step 1 - Import the required modules"""

import pandas as pd
from sklearn.tree import DecisionTreeRegressor 
from sklearn.preprocessing import StandardScaler 
from sklearn.svm import SVR

""" Step 2 - Read the data source"""
SourceData=pd.read_excel("Supplier Past Performance.xlsx") # Load the training data into Pandas DataFrame
Testdata=pd.read_excel("Defect Predict.xlsx") # Load the test data 

""" Step 3  - Declare the independent and dependent train data from the sample"""
SourceData_train_independent= SourceData.drop(["Defect Percent"], axis=1) # Drop depedent variable from training dataset
SourceData_train_dependent=SourceData["Defect Percent"].copy() #  New dataframe with only independent variable value for training dataset

""" Step 4  - Scale the independent test and train data"""
sc_X = StandardScaler()
X_train=sc_X.fit_transform(SourceData_train_independent.values) # scale the independent variables
y_train=SourceData_train_dependent # scaling is not required for dependent variable
X_test=sc_X.transform(Testdata.values)

""" Step 5  - Fit the test data in maching learning model - Support Vector Regressor"""
svm_reg = SVR(kernel="linear", C=1)
svm_reg.fit(X_train, y_train) # fit and train the modelpredictions = svm_reg.predict(X_test)

print("Defect percent prediction by Support Vector model for the order value of 95827 GBP with 851 pallets sent 55 days before delivery data is " ,round(predictions[0],2) , "%")

""" Step 6 - Fit the test data in maching learning model - Decision Tree Model"""
tree_reg = DecisionTreeRegressor()
tree_reg.fit(X_train, y_train) # fit and train the modeldecision_predictions = tree_reg.predict(X_test) # Predict the value of dependent variableprint("Defect percent prediction by Decision Tree model for the order value of 95827 GBP with 851 pallets sent 55 days before delivery data is " ,round(decision_predictions[0],2) , "%")

About the Author

Kaushik Choudhury – Senior Solution Design Architect

Kaushik is a senior solution design architect in one of the big four consulting firms’ Supply Chain capability. He is an experienced business transformation consultant and has delivered a wide range of supply chain programs for leading brands in the UK and continental Europe. Kaushik was involved in designing and delivering solutions in Supply Chain business transformation, business re-engineering, a complete end to end technology roadmap implementation projects covering multiple geographical footprints. You can reach him on twitter @think_kc

 

Responses From Readers

Clear

Dinesh Chauhan
Dinesh Chauhan

Hi, Thanks for the blog & its interesting problem to look into. Could you provide train/test files so that we can try it on out machine. Thanks & Regards

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details