October 09, 2026
Exploration of Patterns related to Order Delivery Time Using Supervised Machine Learning Techniques
Exploration of Patterns Related to Order Delivery Time Using Supervised Machine Learning Techniques
Marcel Borges Andrade; Diego Pedroso dos Santos
DOI: 10.22167/2675-6528-202603227
Article derived from a Final Course Work (TCC), with content based on the student’s original work and adapted to the editorial format of the E&S Magazine with the support of the ResumeAI tool, an artificial intelligence solution developed by Instituto Pecege for textual synthesis and organization.
Summary
The efficiency in delivery time in logistics and e-commerce services represents a crucial challenge. Patterns associated with delivery time were explored, and the performance of supervised machine learning techniques in predicting this variable was compared. A public dataset with 43,739 delivery records was used, including weather conditions, traffic level, vehicle type, agent characteristics, area type, order category, and geographical coordinates, from which the Haversine distance was calculated. Linear Regression, Random Forest, and XGBoost models were compared, with an 80% holdout split for training and 20% for testing, evaluating performance by R², MAE, and RMSE. XGBoost achieved the best result, with an R² of 0.8046, MAE of 17.80 minutes, and RMSE of 22.82 minutes, outperforming Random Forest by a small margin and Linear Regression significantly. Descriptive analyses revealed distinct delivery time distributions across traffic, weather, area, vehicle, and order type categories, with the Category_Grocery category showing the highest predictive importance. The results indicated the existence of relevant predictive structure in the data, but its extrapolation to real logistics operations requires external validation and specific operational data, due to the observational nature of the dataset and limitations such as category imbalance and the absence of external validation.
Keywords: machine learning; urban logistics; predictive modeling; regression; delivery time.
1. Introduction
Efficiency in delivery time represents one of the main challenges faced by logistics and e-commerce companies. This scenario is characterized by the growing demand for fast and reliable services. The advancement of digital marketing and the widespread dissemination of mobile technologies, such as smartphones and tablets, have transformed consumption habits, increasing the frequency of online purchases and consumer expectations regarding service agility. Consumer behavior has been strongly influenced by the digital environment, where there has been a significant increase in the search for products and services online, as well as in consumer interaction through the sharing of experiences (Dwivedi et al., 2021).
Consumption patterns are conditioned by factors such as time availability and location, which directly influence the purchasing decision (Sheth, 2020). This scenario was further intensified by the COVID-19 pandemic, starting in 2020, which boosted demand for delivery services due to the need for social distancing. Such a context amplified the relevance of urban logistics in meeting the needs of the modern consumer.
Given this context, the analysis of factors associated with delivery time becomes relevant for understanding the performance of logistics operations. Variables such as weather conditions, traffic level, vehicle type, distance between origin and destination, and delivery area characteristics can show different relationships with the observed time. Furthermore, many of these factors exhibit high variability and can interact with each other, making delivery time prediction a multivariate and complex problem.
In this scenario, machine learning techniques have been applied to the prediction of delivery times in logistics operations, as demonstrated by Kasoju, Vishwakarma, and Kasoju (2025) in a study on last-mile operations optimization. Machine learning can contribute to the identification of patterns and the construction of predictive models capable of simultaneously using multiple delivery characteristics. In particular, supervised learning is an established approach in the field of Machine Learning, suitable for situations where a known target variable is available and its value is sought to be estimated for new observations.
Supervised learning consists of training computational models based on a dataset where both the predictor variables, or independent ones, and the target variable, or dependent one, are known. From this process, the model learns patterns and relationships between variables, becoming capable of making predictions on new data. The growing use of these techniques in planning and control problems is driven by the ability to identify complex patterns from large volumes of data (Rokoss, 2024). In the context of this work, the target variable is the order delivery time, a continuous numerical variable, estimated from independent variables such as weather conditions, traffic level, vehicle type, distance traveled, delivery person’s age, area type, and product category.
The delivery time forecast presents a relevant challenge from both an analytical and operational point of view. The comparison between different regression techniques allows us to evaluate whether models capable of representing non-linear relationships and interactions between variables present advantages over simpler linear approaches. In addition to predictive performance, the analysis of the characteristics available in the database can contribute to understanding how different conditions are associated with the distribution of delivery times. Thus, this work aimed to apply supervised machine learning techniques to develop predictive models capable of estimating delivery time in urban logistics operations, based on real data. For this purpose, algorithms such as Multiple Linear Regression, Random Forest, and XGBoost were used, with the aim of exploring patterns associated with the explanatory variables and generating insights applicable to decision-making.
2. Material and Methods
The study, of an applied, quantitative, exploratory, and predictive nature, aimed to apply supervised machine learning techniques to estimate delivery time in urban logistics. The analytical procedure included obtaining and inspecting the database, defining and treating variables, and dividing the records into training and testing sets. There was no direct collection of personal data, using a public database, in accordance with the conditions of its availability.
A public database named Amazon Delivery Dataset, available on the Kaggle platform, was used. After inspection and removal of duplicates, the final database comprised 43,739 delivery records. The target variable was Delivery_Time, expressed in minutes. The explanatory variables included Agent_Age, Agent_Rating, Weather, Traffic, Vehicle, Area, Category, and Distance_km, selected for their availability and potential relationship with delivery time.
The variables Agent_Age, Agent_Rating, and Distance_km were treated as numerical, while Weather, Traffic, Vehicle, Area, and Category were considered categorical. The Distance_km variable was calculated from geographic coordinates using the Haversine formula. The data treatment and engineering step was implemented by a preprocessing pipeline, identifying 145 records with missing values (approximately 0.33% of the total) in the Weather and Agent_Rating variables.
For categorical variables, missing values were filled with the most frequent category (mode), using SimpleImputer. For numerical variables, imputation was performed by the mean, using SimpleImputer. The imputation strategy was maintained in the pipeline after comparative analysis. Categorical variables were transformed by one-hot encoding, using OneHotEncoder with the parameters drop=”first” and handle_unknown=”ignore”. Numerical variables were kept in their original scale, and preprocessing was integrated through ColumnTransformer.
Exploratory Data Analysis (EDA) was conducted before modeling to examine patterns and relationships between variables. Python was used with the Pandas and Matplotlib libraries. A correlation matrix was calculated for the numerical variables, and the distribution of delivery time in relation to categorical variables was examined using boxplots. A georeferenced heatmap was created with the Folium library.
Supervised modeling aimed to estimate delivery time. To ensure comparability, the same set of variables and the same preprocessing flow were used for all models. Three regression algorithms were evaluated: Multiple Linear Regression, Random Forest, and XGBoost. Linear Regression served as the baseline model, while Random Forest and XGBoost were employed for their ability to represent nonlinear relationships and attribute interactions (BREIMAN, 2001; CHEN; GUESTRIN, 2016).
The models were implemented in Python, in the Google Colab environment. The model configurations were defined in the code, maintaining the default library values for unspecified parameters. For Random Forest, n_estimators=200, random_state=42, and n_jobs=-1 were defined. In XGBoost, n_estimators=300, learning_rate=0.05, max_depth=6, subsample=0.8, colsample_bytree=0.8, random_state=42, and objective=reg:squarederror were configured.
The evaluation of the models was performed through a holdout split, reserving 80% of the records for training and 20% for testing. The split was performed using the train_test_split function from the Scikit-learn library, utilizing the random_state=42 parameter to ensure reproducibility. For the evaluation of predictive performance, the metrics Coefficient of Determination (R²), Mean Absolute Error (MAE), and Root Mean Squared Error (RMSE) were used. The MAE quantified the average magnitude of prediction errors, and the RMSE was employed as a complementary metric, assigning greater weight to larger errors. Both metrics, MAE and RMSE, were expressed in minutes. The Scikit-learn, xgboost, Pandas, NumPy, Matplotlib, and Seaborn libraries were used in the computational implementation.
3. Results and Discussion
The results obtained in this research allowed for a comparative analysis of the predictive performance of different regression models and the exploration of patterns associated with delivery time in logistics operations. The interpretation of the findings was conducted with the premise that the database used is observational in nature, which implies that statistical associations and variable importance measures do not, in isolation, establish cause-and-effect relationships. In general, the findings reinforce the multifactorial complexity inherent in the delivery time prediction problem, aligning with the literature that addresses the application of machine learning in logistics contexts (Rokoss, 2024).
Performance of predictive models
After the training phase, the evaluation of the models’ performance on the test set revealed that the XGBoost algorithm presented the best overall performance. This model achieved a Coefficient of Determination (R²) of 0.8046, a Mean Absolute Error (MAE) of 17.80 minutes, and a Root Mean Squared Error (RMSE) of 22.82 minutes. The Random Forest model obtained quite close results, with an R² of 0.7910, an MAE of 17.99 minutes, and an RMSE of 23.60 minutes. In contrast, Linear Regression demonstrated significantly inferior performance, with an R² of 0.5843, an MAE of 26.21 minutes, and an RMSE of 33.28 minutes.
The notable difference in performance between Linear Regression and tree-based models, such as Random Forest and XGBoost, suggests that delivery time is influenced by non-linear relationships and complex interactions among attributes, which are not adequately captured by a simple linear approach. The ability of decision tree models to capture these more intricate relationships contributed to their predictive superiority. Although XGBoost outperformed Random Forest, the margin was relatively small, indicating that both non-linear methods exhibited comparable and robust performance for this dataset.
Importance of explanatory variables
The analysis of the importance of the explanatory variables, performed based on the XGBoost model after transforming categorical variables using One-Hot Encoding, revealed the predictive contribution of each attribute. It is fundamental to interpret the importance of a transformed variable as a measure of its utility for the tree splits in the model, and not as a direct indication of the magnitude of the causal effect or the direction of the relationship. The derived variable Category_Grocery stood out with the highest importance, contributing approximately 60.3% of the normalized average gain, suggesting that the distinction between records in this category and others was particularly effective in reducing prediction error.
The predominance of the Category_Grocery variable, however, should be interpreted with caution. Although it is a strong predictive indicator, its high importance may reflect specific operational patterns or intrinsic characteristics of this category in the analyzed database, and not necessarily a generalizable causal effect. Other variables, such as those associated with traffic level (Traffic Low, Traffic Jam), weather conditions (Weather Sunny, Weather Fog, Weather Stormy), agent evaluation (Agent Rating), area type (Area Semi-Urban), agent age (Agent Age), and vehicle type (Vehicle motorcycle), also contributed to the predictive performance, albeit with a lower relative importance than Category_Grocery. The Distance_km variable, despite being a utilized attribute, did not prove to be a primary determinant in the XGBoost importance measure, which reinforces that predictive importance depends on the model structure and does not imply causality.
Distributions, extreme values, and differences between categories
The descriptive analysis of delivery time distributions in relation to the categorical variables Traffic, Weather, Area, and Vehicle revealed important differences. Regarding the Traffic variable, the Low category presented a median of 100 minutes, concentrating 202 of the 230 outliers identified, which corresponds to 1.35% of the 14,999 records in this category. In contrast, the Jam category, with a median of 150 minutes, did not register observations classified as outliers by the same criterion. The concentration of extreme values in the Low category does not indicate that low traffic conditions result in longer delivery times, but rather that, within a group with typically faster behavior, atypical cases of exceptionally long deliveries occur, exceeding the upper limit of the interquartile range.
Regarding the Weather variable, the Sunny condition exhibited the lowest delivery time median, with 100 minutes, but also concentrated 302 upper outliers, representing 4.27% of the 7,078 records in the category. The Cloudy and Fog conditions presented medians of 140 and 135 minutes, respectively, with no observations classified as outliers. This pattern suggests that favorable weather conditions can sometimes coexist with exceptionally long deliveries, indicating the influence of other operational characteristics that vary simultaneously and reinforcing the multivariate nature of the problem. The upper outliers in Sunny, therefore, do not contradict the lowest median observed, but rather highlight the complexity of the interactions between factors.
For the Area variable, the Semi-Urban category presented a median of 245 minutes, with an interquartile range between 238.75 and 261.25 minutes. Eight outliers were identified among the 152 records in this category, corresponding to 5.26%. Unlike the other cases, all these extreme values were below the lower limit of the boxplot, indicating exceptionally faster deliveries within a group that typically exhibits longer times. This observation should be interpreted with caution, as the Semi-Urban category represents only about 0.35% of the database. A possible interpretation, without causal attribution, is that the Area variable may be capturing aspects of access, infrastructure, or road network that are not fully represented by the straight-line distance calculated by Haversine.
Regarding the vehicle type, Motorcycle presented a median of 130 minutes, while Scooter and Van registered medians of 115 minutes. Outliers were infrequent, with 46 records in Scooter and seven in Van, totaling 53 observations. The interpretation of differences between vehicle types requires caution due to the unequal size of the categories. The Bicycle category, for example, has only 15 records, in contrast to 25,527 for Motorcycle, 14,639 for Scooter, and 3,558 for Van. The observed differences for categories with low representativeness do not provide a sufficient basis for robust conclusions and should not be interpreted as direct causal effects of the transport mode.
Visual assessment of predictions
The comparison between the actual values and the values predicted by the XGBoost model demonstrated a relevant concentration of points close to the identity line, which is in agreement with the quantitative performance metrics obtained. This proximity indicates that the model is capable of making predictions with good accuracy for most records. However, the dispersion still observed in some records suggests that the model does not fully reproduce all the variability of the delivery time. This visual representation serves as complementary evidence of the model’s performance on the test set, but should not be interpreted as a demonstration of robustness for external bases or operations.
Integrated discussion of findings
The joint analysis of the results indicates that the delivery time prediction benefits significantly from the combination of operational, environmental, spatial, and order characteristics. The superior performance of tree-based models, compared to Linear Regression, suggests the existence of nonlinear patterns and complex interactions among attributes that are not adequately represented by a simple linear relationship. This finding reinforces the suitability of more flexible machine learning techniques for logistical problems with multiple interconnected factors.
The categorical distributions analyzed also evidenced the importance of distinguishing typical behavior, variability, and the occurrence of extreme values. Categories with lower medians, such as Low in Traffic and Sunny in Weather, may present a higher proportion of upper outliers due to their central distribution being situated at lower levels. On the other hand, the Semi-Urban category, with high typical weather, presented lower outliers, indicating that extreme values can represent both exceptionally long delays and exceptionally fast deliveries, depending on the specific distribution of each group. Careful interpretation of these patterns is crucial to avoid erroneous conclusions about operational performance.
From an applied perspective, the results demonstrate that machine learning techniques can be valuable tools for identifying relevant predictive patterns in delivery data. However, the interpretation of these patterns must remain restricted to the analyzed dataset, given its observational nature and the absence of external validation. The high importance of the Category_Grocery category, the low representativeness of categories such as Semi-Urban and Bicycle, and the limitation of the distance calculated by Haversine, which does not incorporate real route characteristics, recommend caution in extrapolating the results to distinct logistical operations. The methodology employed, including the comparison between imputation and exclusion of missing values, also highlighted the importance of explicit and reproducible data treatment.
The results obtained in this study should be interpreted considering the characteristics and limitations of the dataset used. As it is a public and observational database, the identified patterns reflect the relationships present in this sample and do not allow for the establishment of causal relationships nor assurance that the performance obtained will be reproduced in distinct logistic operations. The absence of external validation constitutes a relevant limitation for the generalization of the results. Furthermore, the unequal representativeness between some categories, such as the Semi-Urban category with only 152 records and Bicycle with only 15 records, in contrast to larger categories like Metropolitan (32,698 observations) and Motorcycle (25,527 observations), reduces the robustness of the comparisons and may lead to estimates with greater uncertainty for these groups. The differences observed in these categories should be interpreted with caution and not generalized to other operations.
The variable Distance_km, calculated by the Haversine formula, represents the straight-line distance between origin and destination, which is an approximation that does not incorporate characteristics of the effectively traveled route, such as road direction, traffic lights, local congestion, roadworks, terrain, and other road network restrictions. In operational applications, the use of distances and travel times obtained from real routes could broaden the spatial representativeness of the models. From a methodological standpoint, the absence of a systematic search for hyperparameters and cross-validation, with the adoption of an 80% training and 20% testing holdout split, was sufficient for the proposed comparison, but future studies may incorporate more robust approaches to evaluate the consistency of the results.
In summary, this study demonstrated that supervised machine learning techniques are effective in exploring predictive structures in delivery data and in comparing different regression strategies. The XGBoost model presented the best performance, with an R² of 0.8046, an MAE of 17.80 minutes, and an RMSE of 22.82 minutes, indicating that the combination of operational, environmental, spatial, and order characteristics contributes to delivery time prediction. Descriptive analyses revealed distinct patterns in delivery time distributions across traffic, weather, area, and vehicle type categories, with the Category_Grocery category showing the highest predictive importance. These findings, although promising, should be interpreted within the limitations of the database used, which is observational and public, and require external validation and specific operational data for their extrapolation to real logistical contexts.
4. Conclusion
This study aimed to apply supervised machine learning techniques to estimate delivery time in urban logistics operations and explore patterns associated with this variable, using real data. It was found that the XGBoost algorithm presented the best predictive performance, with an R² of 0.8046, a Mean Absolute Error of 17.80 minutes, and a Root Mean Squared Error of 22.82 minutes, outperforming Random Forest and, more markedly, Linear Regression. This superiority of tree-based models indicated the existence of nonlinear relationships and complex interactions among the attributes influencing delivery time. Descriptive analyses revealed distinct patterns in delivery time distributions across traffic, weather, area, and vehicle type categories, with the Category_Grocery category demonstrating the highest predictive importance. The results highlight that machine learning techniques are valuable tools for identifying relevant predictive structures in delivery data, contributing to the understanding of logistics performance.
However, the findings should be interpreted considering the study’s limitations, such as the observational nature of the public database, the absence of external validation, and the unequal representativeness of some categories, which prevent causal generalization to distinct logistical operations. The Haversine distance, being a straight-line approximation, did not incorporate real route characteristics, and the methodology did not include systematic hyperparameter search or cross-validation. For future studies, it is suggested to apply the models to real and independent operational databases, include dynamic variables such as real-time traffic conditions and route information, and use explainability techniques to deepen the interpretation of patterns and evaluate the transferability of the models in different contexts.
Bibliographic References
BREIMAN, L. (2001). Random Forests. Machine Learning, 45, 5-32. https://doi.org/10.1023/A:1010933404324
CHEN, T.; GUESTRIN, C. (2016). XGBoost: A Scalable Tree Boosting System. Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 785-794. https://doi.org/10.1145/2939672.2939785
DWIVEDI, Y. K., et al. (2021) Setting the future of digital and social media marketing research: Perspectives and research propositions. International Journal of Information Management, 59, 102168. https://doi.org/10.1016/j.ijinfomgt.2021.102168
KASOJU, A.; VISHWAKARMA, T.; KASOJU, A. (2025). The role of Al-enhanced fast delivery services in strengthening customer retention and loyalty in competitive markets. Frontiers in Artificial Intelligence, 8, 1612772. https://doi.org/10.3389/frai.2025.1612772
ROKOSS, J. Machine learning-based prediction of delivery times in manufacturing environments. 2024. Disponível em: https://d-nb.info/1324398027/34. Acesso em: 19 abr. 2026.
Sheth, 2020 [Full reference not found in the original document]
Article originating from the Final Course Work of the Specialization in Data Science and Analytics of the MBA USP/Esalq
To learn more about the course, click here and access the MBX Academy platform