Delivery Time Estimation in SC Using Regression Models

The study compares and selects the best linear regression model to improve delivery times in the pharmaceutical industry, makes predictions.
0 Downloads
Updated 12 Feb 2026

View License

In the pharmaceutical industry, delivery time, a key performance metric in the supply chain, is crucial for ensuring patients receive treatment on time and for the uninterrupted delivery of healthcare services. Regression modeling in machine learning aims to improve product delivery times and increase the accuracy of predictions. This study will compare linear regression models, and the most successful model will be used for prediction.
Model Type: Tree
function [trainedModel, validationRMSE] = trainRegressionModel(trainingData, responseData)
% [trainedModel, validationRMSE] = trainRegressionModel(trainingData,
% responseData)
% Returns a trained regression model and its RMSE. This code recreates the
% model trained in Regression Learner app. Use the generated code to
% automate training the same model with new data, or to learn how to
% programmatically train models.
%
% Input:
% trainingData: A table containing the same predictor columns as those
% imported into the app.
%
% responseData: A vector with the same data type as the vector
% imported into the app. The length of responseData and the number of
% rows of trainingData must be equal.
%
%
% Output:
% trainedModel: A struct containing the trained regression model. The
% struct contains various fields with information about the trained
% model.
%
% trainedModel.predictFcn: A function to make predictions on new data.
%
% validationRMSE: A double representing the validation RMSE. In the
% app, the Models pane displays the validation RMSE for each model.
%
% Use the code to train the model with new data. To retrain your model,
% call the function from the command line with your original data or new
% data as the input arguments trainingData and responseData.
%
% For example, to retrain a regression model trained with the original data
% set T and response Y, enter:
% [trainedModel, validationRMSE] = trainRegressionModel(T, Y)
%
% To make predictions with the returned 'trainedModel' on new data T2, use
% yfit = trainedModel.predictFcn(T2)
%
% T2 must be a table containing at least the same predictor columns as used
% during training. For details, enter:
% trainedModel.HowToPredict
% Auto-generated by MATLAB on 12-Feb-2026 20:30:24
% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
predictorNames = {'DeliveryDate', 'Distance_KM_', 'Humidity', 'InvoicedQty', 'No_OfTrucksMadeDelivery', 'Precipitation', 'Temperature', 'ADANA', 'AFYON', 'AKSARAY', 'AMASYA', 'ANKARA', 'ANTALYA', 'AYDIN', 'BALIKESİR', 'BATMAN', 'BOLU', 'BURSA', 'DENİZLİ', 'DÜZCE', 'DİYARBAKIR', 'EDİRNE', 'ELAZIĞ', 'ERZURUM', 'ESKİŞEHİR', 'GAZİANTEP', 'GİRESUN', 'HATAY', 'ISPARTA', 'KAHRAMANMARAŞ', 'KARABÜK', 'KASTAMONU', 'KAYSERİ', 'KIRIKKALE', 'KIRKLARELİ', 'KOCAELİ', 'KONYA', 'KÜTAHYA', 'MALATYA', 'MANİSA', 'MARDİN', 'MERSİN', 'MUĞLA', 'NEVŞEHİR', 'ORDU', 'RİZE', 'SAKARYA', 'SAMSUN', 'SİVAS', 'TEKİRDAĞ', 'TOKAT', 'TRABZON', 'UŞAK', 'VAN', 'YALOVA', 'ZONGULDAK', 'ÇANAKKALE', 'ÇORUM', 'İSTANBUL', 'İZMİR', 'İÇEL', 'ŞANLIURFA', '1', '2', '3', '4', 'March', 'November', 'October'};
predictors = inputTable(:, predictorNames);
response = responseData;
isCategoricalPredictor = [false, false, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
% Train a regression model
% This code specifies all the model options and trains the model.
regressionTree = fitrtree(...
predictors, ...
response, ...
'MinLeafSize', 12, ...
'Surrogate', 'off');
% Create the result struct with predict function
predictorExtractionFcn = @(t) t(:, predictorNames);
treePredictFcn = @(x) predict(regressionTree, x);
trainedModel.predictFcn = @(x) treePredictFcn(predictorExtractionFcn(x));
% Add additional fields to the result struct
trainedModel.RequiredVariables = {'DeliveryDate', 'Distance_KM_', 'Humidity', 'InvoicedQty', 'No_OfTrucksMadeDelivery', 'Precipitation', 'Temperature', 'ADANA', 'AFYON', 'AKSARAY', 'AMASYA', 'ANKARA', 'ANTALYA', 'AYDIN', 'BALIKESİR', 'BATMAN', 'BOLU', 'BURSA', 'DENİZLİ', 'DÜZCE', 'DİYARBAKIR', 'EDİRNE', 'ELAZIĞ', 'ERZURUM', 'ESKİŞEHİR', 'GAZİANTEP', 'GİRESUN', 'HATAY', 'ISPARTA', 'KAHRAMANMARAŞ', 'KARABÜK', 'KASTAMONU', 'KAYSERİ', 'KIRIKKALE', 'KIRKLARELİ', 'KOCAELİ', 'KONYA', 'KÜTAHYA', 'MALATYA', 'MANİSA', 'MARDİN', 'MERSİN', 'MUĞLA', 'NEVŞEHİR', 'ORDU', 'RİZE', 'SAKARYA', 'SAMSUN', 'SİVAS', 'TEKİRDAĞ', 'TOKAT', 'TRABZON', 'UŞAK', 'VAN', 'YALOVA', 'ZONGULDAK', 'ÇANAKKALE', 'ÇORUM', 'İSTANBUL', 'İZMİR', 'İÇEL', 'ŞANLIURFA', '1', '2', '3', '4', 'March', 'November', 'October'};
trainedModel.RegressionTree = regressionTree;
trainedModel.About = 'This struct is a trained model exported from Regression Learner R2025b.';
trainedModel.HowToPredict = sprintf('To make predictions on a new table, T, use: \n yfit = c.predictFcn(T) \nreplace ''c'' with the name of the variable that is this struct, e.g. ''trainedModel''. \n \nThe table, T, must contain the variables returned by: \n c.RequiredVariables \nVariable formats (e.g. matrix/vector, datatype) must match the original training data. \nAdditional variables are ignored. \n \nFor more information, see <a href="matlab:helpview(fullfile(docroot, ''stats'', ''stats.map''), ''appregression_exportmodeltoworkspace'')">How to predict using an exported model</a>.');
% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
predictorNames = {'DeliveryDate', 'Distance_KM_', 'Humidity', 'InvoicedQty', 'No_OfTrucksMadeDelivery', 'Precipitation', 'Temperature', 'ADANA', 'AFYON', 'AKSARAY', 'AMASYA', 'ANKARA', 'ANTALYA', 'AYDIN', 'BALIKESİR', 'BATMAN', 'BOLU', 'BURSA', 'DENİZLİ', 'DÜZCE', 'DİYARBAKIR', 'EDİRNE', 'ELAZIĞ', 'ERZURUM', 'ESKİŞEHİR', 'GAZİANTEP', 'GİRESUN', 'HATAY', 'ISPARTA', 'KAHRAMANMARAŞ', 'KARABÜK', 'KASTAMONU', 'KAYSERİ', 'KIRIKKALE', 'KIRKLARELİ', 'KOCAELİ', 'KONYA', 'KÜTAHYA', 'MALATYA', 'MANİSA', 'MARDİN', 'MERSİN', 'MUĞLA', 'NEVŞEHİR', 'ORDU', 'RİZE', 'SAKARYA', 'SAMSUN', 'SİVAS', 'TEKİRDAĞ', 'TOKAT', 'TRABZON', 'UŞAK', 'VAN', 'YALOVA', 'ZONGULDAK', 'ÇANAKKALE', 'ÇORUM', 'İSTANBUL', 'İZMİR', 'İÇEL', 'ŞANLIURFA', '1', '2', '3', '4', 'March', 'November', 'October'};
predictors = inputTable(:, predictorNames);
response = responseData;
isCategoricalPredictor = [false, false, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
% Perform cross-validation
partitionedModel = crossval(trainedModel.RegressionTree, 'KFold', 10);
% Compute validation predictions
validationPredictions = kfoldPredict(partitionedModel);
% Compute validation RMSE
validationRMSE = sqrt(kfoldLoss(partitionedModel, 'LossFun', 'mse'));
Minimum MSE Plot for Model 5
Response Plot for Predictions
Validation Predicted vs. Actual Plot for Predictions
Shapley Importance for Model 5
Results Comparision

Cite As

Ecem Sude Bıyıklı, Dr Mert Akin Insel (2026). Delivery Time Estimation in SC Using Regression Models (https://www.mathworks.com/matlabcentral/fileexchange/<...>), MATLAB Central File Exchange. Retrieved February 12, 2026.

MATLAB Release Compatibility
Created with R2025b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags
Version Published Release Notes
1.0.0