# Clustering Analysis for Forecasting Medicine Consumption

Douglas Mateus Machado, Zakaria Yahouni, Gülgün Alpan, Denis Koala

► To cite this version:

Douglas Mateus Machado, Zakaria Yahouni, Gülgün Alpan, Denis Koala. Clustering Analysis for Forecasting Medicine Consumption. 5th IFAC/INSTICC International Conference on Innovative Intelligent Industrial Production and Logistics (IN4PL), Nov 2024, Porto, Portugal. hal-04922215

HAL Id: hal-04922215

https://hal.science/hal-04922215v1

Submitted on 30 Jan 2025

**HAL** is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Clustering Analysis for Forecasting Medicine
Consumption

Douglas Mateus Machado¹, Zakaria Yahouni¹, Gülgün Alpan¹, and Denis
Koala²

¹ Univ. Grenoble Alpes, CNRS, Grenoble INP G-SCOP, 38000 Grenoble, France
douglas.mateus-machado@grenoble-inp.org
zakaria.yahouni, gulgun.alpan@grenoble-inp.fr

² KLS-GROUP, 38240 Meylan, France
koala@kls-group.fr

**Abstract.** This study investigates machine learning for forecasting medicine consumption in hospitals to optimize resource allocation and logistics. We use two approaches: a unified approach that combines data from multiple hospitals and a separated approach that forecasts for individual hospitals. We explored both K-means clustering and manual pair clustering based on consumption trends. While K-means clustering did not yield improvements, manual clustering identified specific pairs of medicines with significantly enhanced forecast accuracy (e.g., Medicine 15 at Hospital 1: MAPE decreased from 19.70% to 3.30%). However, the unified approach did not consistently benefit all hospitals (e.g., Medicine 9). This underscores the need to balance accuracy gains in some hospitals against potential losses in others. Overall, manual clustering within the separated approach shows promise. Future work should explore advanced automated clustering techniques like Dynamic Time Warping (DTW) and leverage larger datasets for further validation.

**Keywords:** Medicine consumption · forecasting demand · Machine learn-
ing · Clustering

# 1 Introduction

The healthcare sector, particularly in France is evolving within a complex and dynamic environment [1]. With hospital budgets shrinking over the years, reducing logistics and process costs can profoundly impact the longevity and quality of healthcare services. Therefore, optimizing resource management is essential because of these ongoing budget constraints and the imperative to maintain high-quality patient care [16]. Hospital's supplies and products, such as medicines, represent a significant portion of healthcare expenditures [21], [17]. Therefore, pharmaceutical logistics, accounting for a significant portion of hospital budgets, is a critical area for optimization. Understanding hospital medicine demand (consumption) is fundamental to achieving this optimization [9], [22].

Various factors, including socio-demographic, socioeconomic, health-related,
facility-related, staff-related aspects, inappropriate use of medication in some
facilities, affect medicine consumption dynamics and are crucial for forecasting demand [12] [3] [4]. Furthermore, each region and country has its own cultural and specific factors that influence these dynamics. These findings align with the broader literature on healthcare supply chain management and the critical role of demand forecasting in optimizing pharmaceutical logistics [2], [14], [20].

When dealing with forecasting in healthcare sector, machine learning tech-
niques have a good potential [15]. In this context, few works deal with forecasting
medicine consumption such as [3] and [11]. In the work of [3] for instance, authors
proposed prediction framework using short time-series. The consistency of the
prediction was performed on data taken from 21 Italian regions. [12] in collabo-
ration with a private sector company in France, highlighted and explored various
factors influencing medicine consumption in French hospitals through qualita-
tive analysis. A correlation analysis followed this to investigate key quantitative
relationships [11]. Then, these factors were implemented in various techniques
such as machine learning and Markov chain-based predictive approaches, to pre-
dict medicine consumption in French hospitals [13], [22]. Our work relies on the
data used in these studies.

The result of these previous studies showed that Machine Learning (ML)
techniques offer innovative solutions for predicting medicine consumption pat-
terns with good accuracy. However, as each medicine can be impacted differently
by the identified factors [12], each medicine needs to have it specific ML model.
Due to the limited data for each medicine, training and implementing a specific
ML model for each medicine is not practical. Moreover, the accuracy of some ML
algorithms for some medicines was not satisfactory, mostly due to a limited num-
ber of data. Our primary aim in this paper is to investigate clustering techniques
in predicting medicine consumption. The aim is to propose a machine-learning
model for a group of medicines instead of each medicine. This approach has two
advantages that can cope with the literature gaps: first, reducing the number
of models needed to forecast consumption accurately, and second, overcoming
difficulties related to limited data.

To achieve this goal, and primarily the clustering aim, our study applies the K-means clustering technique. The effectiveness of these clusters is evaluated using the Random Trees Regressor model, which has demonstrated potential in previous research for handling complex datasets [8], [6], [19], [7].

Forecasting medicine consumption based on clustered data proved challeng-
ing because of the limited data quantity and unknown factors linking consump-
tion patterns across different hospitals. The classical clustering method (K-means
clustering) did not yield satisfactory results during the forecasting phase. To ex-
plore an alternative approach, we manually compared all pairs of medicines to
identify similarities based on consumption trends. This approach produced more
satisfactory results than the baseline model, which involved creating a separate
prediction model for each medicine from each hospital.

The goal is to develop robust forecasting tools that hospital administrators
can use to plan and allocate resources more effectively. These improvements
can lead to significant cost savings and more efficient allocation of resources,
ultimately enhancing patient outcomes and operational efficiency.

The paper is structured as follows: as this section deals with the context
background, Section 2 describes the dataset, the clustering and forecasting tech-
niques used, and the methodology adopted. Section 3 and 4 present the findings,
including metrics and insights from the analysis, and compare different cluster-
ing approaches. Last section summarizes the key contributions of the study and
suggests directions for future research.

## 2 Proposed approach

Starting with the structured database developed in previous studies, we em-
ployed a systematic approach comprising the following steps: data formatting,
data treatment, feature manipulation and comprehension, clustering, and eval-
uation through forecasting.

The dataset included information on hospital size (number of departments),
population served, year and month of consumption for each medicine. It required
formatting and treatment before applying clustering and forecasting techniques.

Figure 1 illustrates the simplified steps leading to the creation of five treated
databases. It also shows how the database was used to apply and evaluate clus-
tering techniques, and subsequently analyze the clustering results for medicine
consumption forecasting.

2.1 Data Formatting, Treatment and Feature Engineering

The dataset used in this research includes 21 of the most commonly consumed
medicines in four different hospitals in France. 12 features were collected for
each medicine, such as number of hospital medical units where the medicine
is consumed, number of physician in the hospital, etc. All these features are
taken from [12], [11]. We add to these features, factors related to seasonality
to find relationships between these factors and cluster different medicines. This
approach can reduce the number of models required for accurate consumption
forecasting.

The data distribution (number of lines) for the different hospitals is presented
in Fig.2. The original dataset comprised 75,684 data points ( [12], [11]). The first
hospital contributed 22,725 inputs, representing 30.03% of the data. The second,
third, and fourth hospitals represent respectively 20.40%, 36.45% and 13.12% of
the total data. After aggregating the data per month, the input amount was
4072 with 1208 from hospital 1 (29.66%), 697 from hospital 2 (17.12%), 1397
from hospital 3 (34.31%) and 770 from hospital 4 (18.91%)

As presented in Fig.1, different sub-steps were applied to test and validate
two main approaches, leading to two sets of files (five databases):

- **Unified approach:** In this approach, all data from four hospitals are grouped
in a single database.
<figure><img src="image_2.png" /><figcaption>Fig. 1: Simplified pipeline of data processing, clustering and forecasting</figcaption></figure>
<figure><img src="image_3.png" /><figcaption>Fig. 2: Data distribution for the four different hospitals</figcaption></figure>

- **Dividing database by hospital**: Four databases are generated. Each one concerns one of the four hospitals. In this approach, all the next steps are applied to each of the four databases separately.

As data from four hospitals ranges over different periods, data was selected based on a common consumption period between the four hospitals to establish the same basis for comparison, as illustrated in Fig. 3.

The aim of selecting common periods is to ensure fair comparison across different hospitals when predicting medicine consumption. It's worth noting that the selected period does not include the SARS-CoV-2 era. However, these choices resulted in a limited amount of data for training and testing the models. After aggregating the data inputs per month and selecting a common period from March 2017 to March 2019, the distribution was as follows: the total number of data points was 1995. Hospital 1 had 459 entries (23.01%), Hospital 2 had 508 entries (25.46%), Hospital 3 had 524 entries (26.27%), and Hospital 4 had 504 entries (25.26%).

During these steps, inputs were aggregated by medicine, hospital, year, and month. Data were grouped by month of consumption because it is our targeted unit of prediction. Categorical features were transformed using one-hot encoding to facilitate the application of numerical methods.

In the feature engineering step, the correlation analysis between the different data of the treated dataset was performed in order to select the most relevant information to build the clustering and forecasting models. Multi-objective decision support techniques are appropriate for the identification of accurate and robust multivariate time series forecasting models [10]. For this work, seasonal
<figure><img src="image_4.png" /><figcaption>Fig. 3: Temporal union by a common period for the 4 hospitals</figcaption></figure>

decomposition was employed to gain a deeper understanding of the trends and time-related variations in medicine consumption [23], [13]. The trends were later found to be very useful when applying the manual clustering method. Fig. 4 presents an example of the created features.

Seasonal decomposition of the time series involved breaking down the consumption quantity of the medicine into four distinct components: quantity, trend, seasonal, and residual. The quantity represents the actual observed data over time. The trend component captures the long-term progression of the data, showing whether the consumption is generally increasing or decreasing. The seasonal component reflects the recurring patterns or cycles that repeat over a fixed period, such as monthly or yearly fluctuations in medicine usage. Last, the residual component accounts for the irregular or random variations in the data that are not explained by the trend or seasonal components. By analyzing these features, we can better understand the underlying factors influencing medicine consumption, enabling more accurate forecasting and informed decision-making.

The output of these steps is two sets of files: one containing combined data from all four hospitals, resulting in a larger dataset, and another set composed of four separate files, each corresponding to an individual hospital, resulting in fewer data entries per file.

## 2.2 Clustering

To achieve the clustering aim, an analytical causal methodology was employed. This method considers the entire dataset to understand the underlying factors driving medicine use.
<figure><img src="image_5.png" /><figcaption>Fig. 4: Example of seasonal decomposition of time series for a medicine</figcaption></figure>

For the clustering portion of the study, the K-means technique was selected. K-means clustering offers several advantages, including simplicity, computational efficiency, and ease of implementation and scalability for large datasets. It provides clear and distinct cluster assignments, effectively discovers underlying patterns and groupings, and its centroid-based approach helps create well-separated and balanced clusters, making the results easier to interpret and analyze.

Given that the aforementioned techniques did not yield satisfactory results in the forecasting section of the study as illustrated in the result section, an alternative approach was considered. This involved manually pairing all medicines from various hospitals to compare their consumption trends, which might potentially show similarities and clustering possibilities for prediction purposes.

The chosen metrics to evaluate the clustering techniques were the silhouette score and the Davies-Bouldin index, as they are commonly used to assess clustering quality. The Davies-Bouldin Index measures the average similarity between each cluster and its most similar cluster, where lower values show better clustering. The Silhouette Score quantifies how similar an object is to its own cluster compared to other clusters, with values ranging from -1 to 1; higher scores suggest better-defined clusters. These metrics provide objective assessments of clustering performance, aiding in selecting the most suitable clustering algorithm and parameter settings. For the unified approach, the metrics scores for the K-means algorithm are presented in Fig. 5.
<figure><img src="image_6.png" /><figcaption>Fig. 5: Metrics scores for the k-means algorithm</figcaption></figure>

The figure shows that the optimal cluster composition occurs with *k* = 3. This insight is valuable for the forecasting step, as it allows for the testing and evaluation of both approaches. For the unified approach or the approach using data separated per hospital, all the 21 medicines were in each cluster, varying by the date or other features of the dataset.

To apply the manual clustering methodology, combinations of medicines and hospitals were created, such as Medicine A from Hospital X paired with Medicine B from Hospital Y. This approach allowed for a visual comparison of trends between the same medicine from different hospitals or different medicines from the same or different hospitals. To find the total number of possible combinations of medicines, we considered two cases: (1) choosing medicines from different hospitals and (2) choosing different medicines from the same hospital. For different hospitals, there are $\binom{4}{2} \times 21^2 = 6 \times 441 = 2646$ combinations. For the same hospital, there are $\binom{4}{1} \times \binom{21}{2} = 4 \times 210 = 840$ combinations. Adding these, the total number of possible combinations is $2646 + 840 = 3486$.

This idea was based on trends observed during the seasonal decomposition in the feature engineering step. Despite varying consumption magnitudes, some medicines exhibited very similar behaviors, prompting an investigation into combining pairs, trios, and quartets. However, as a first investigation, this study focuses on pairs of medicines and their respective performance in the evaluation (forecasting) step.

At this stage, we labeled the inputs from various hospitals based on the clusters generated using different methods. Since we have multiple records for each medicine recorded at different times and with different features, it's common for parts of the data to be grouped into each cluster for all 21 medicines. This occurs because medicine consumption patterns are complex and can vary because of factors like patient demographics, seasons, and treatment approaches. Consequently, one medicine may show different usage patterns across clusters, illustrating how its use varies within the healthcare system.

## 2.3 Forecasting

For the evaluation method, we implemented random forest regressor models to forecast medicine consumption based on the identified clusters. Random forest
regressors are helpful because of their robustness, ability to handle large datasets,
and ease of interpretability. The process begins by selecting a single medicine
or a set of medicines from the same or different hospitals. The dataset is then
divided into a training set (85%) and a test set (15%). Fig.6 illustrates the steps
implemented in the forecasting process to evaluate the clusters' quality.

<figure><img src="image_7.png" /><figcaption>Fig. 6: Process of Forecasting medicine consumption</figcaption></figure>

The data, whether from the unified or separated datasets, is used to select
either a single medicine or a cluster of medicines. The random forest regressor
is initialized with specific parameters and cross-validated using a 5-fold strategy
to ensure reliability and prevent overfitting. Grid search is then employed to
fine-tune the model by systematically testing different parameter combinations
to find the optimal settings. Finally, the fine-tuned model is used to forecast
the medicine quantities in the test set, providing insights into the expected con-
sumption patterns. This method offers an effective and comprehensible approach
to accurately predict medicine demand.

To ensure a robust analysis, this study emphasizes the manual clustering
technique because of its superior performance in yielding relevant results. The
subsequent sections will concentrate on this method. A baseline comparison was
established using the Mean Absolute Percentage Error (MAPE) metric, which is
particularly well-suited for evaluating forecast models in the context of medicine
consumption [5], [18] and availability in hospitals. MAPE provides a clear, in-
tuitive percentage that reflects the average deviation of the forecasts from the
actual figures, offering a proportional accuracy that is critical for effective inven-
tory management in healthcare settings. This metric was applied to a curated
dataset comprising various medicines across different hospitals, allowing precise
evaluation of the clustering technique's effectiveness on a per-hospital basis. Ac-
curate forecasts, showed by a low MAPE value, are essential for hospitals to
ensure the right medicines are available when needed, avoiding overstock and minimizing waste.

To facilitate the comparison of results for the various tested medicines, it is crucial to establish a guideline. A baseline was developed by creating a forecasting model for each medicine from each hospital. This baseline serves as a reference point, providing an objective to be achieved. A cluster is considered effective if it outperforms the baseline, showing improved forecasting accuracy.

# 3 Results and Comparison

## 3.1 Forecasting per hospital and medicine without clustering (baseline forecasting)

To facilitate a comparative analysis, the baseline for forecasting medicine consumption was established using the same pipeline as the manual clustering. However, it was executed individually for each hospital and specific medicine. The outcomes of this process are systematically presented in Table 1, detailing the baseline results for each hospital, from the 21 medicines.
<table><caption>Table 1: Baseline per hospital</caption><thead><tr><th>Medicine</th><th>Hospital 1</th><th>Hospital 2</th><th>Hospital 3</th><th>Hospital 4</th></tr></thead><tbody><tr><td>Medicine 1</td><td>11.80%</td><td>9.20%</td><td><strong>8.60%</strong></td><td>18.00%</td></tr><tr><td>Medicine 2</td><td>13.10%</td><td>12.50%</td><td>20.40%</td><td><strong>3.80%</strong></td></tr><tr><td>Medicine 3</td><td>13.80%</td><td><strong>13.60%</strong></td><td>29.50%</td><td>20.70%</td></tr><tr><td>Medicine 4</td><td>7.40%</td><td>14.50%</td><td><strong>4.20%</strong></td><td>7.10%</td></tr><tr><td>Medicine 5</td><td>17.40%</td><td>19.80%</td><td><strong>13.90%</strong></td><td>21.90%</td></tr><tr><td>Medicine 6</td><td>12.40%</td><td>27.20%</td><td><strong>4.00%</strong></td><td>5.60%</td></tr><tr><td>Medicine 7</td><td>25.10%</td><td>15.90%</td><td><strong>4.90%</strong></td><td>11.40%</td></tr><tr><td>Medicine 8</td><td>10.80%</td><td>9.10%</td><td><strong>8.30%</strong></td><td>26.50%</td></tr><tr><td>Medicine 9</td><td>10.00%</td><td><strong>4.00%</strong></td><td>9.50%</td><td>17.00%</td></tr><tr><td>Medicine 10</td><td>12.20%</td><td>15.60%</td><td>11.80%</td><td><strong>9.40%</strong></td></tr><tr><td>Medicine 11</td><td>24.20%</td><td><strong>10.50%</strong></td><td>222.10%</td><td>19.50%</td></tr><tr><td>Medicine 12</td><td><strong>3.10%</strong></td><td>21.30%</td><td>9.50%</td><td>8.00%</td></tr><tr><td>Medicine 13</td><td>18.10%</td><td><strong>9.40%</strong></td><td>14.70%</td><td>12.30%</td></tr><tr><td>Medicine 14</td><td><strong>6.40%</strong></td><td>12.60%</td><td>8.40%</td><td>16.00%</td></tr><tr><td>Medicine 15</td><td>19.70%</td><td><strong>17.00%</strong></td><td>38.60%</td><td>27.00%</td></tr><tr><td>Medicine 16</td><td><strong>9.50%</strong></td><td>33.80%</td><td>18.30%</td><td>24.20%</td></tr><tr><td>Medicine 17</td><td>22.70%</td><td><strong>2.90%</strong></td><td>6.30%</td><td>11.10%</td></tr><tr><td>Medicine 18</td><td><strong>10.90%</strong></td><td>39.10%</td><td>17.00%</td><td>26.70%</td></tr><tr><td>Medicine 19</td><td>9.40%</td><td><strong>4.10%</strong></td><td><strong>4.10%</strong></td><td>7.00%</td></tr><tr><td>Medicine 20</td><td>25.40%</td><td>18.20%</td><td><strong>15.00%</strong></td><td>21.30%</td></tr><tr><td>Medicine 21</td><td>30.50%</td><td><strong>11.20%</strong></td><td>14.90%</td><td>20.20%</td></tr></tbody></table>

The table illustrates the variance in forecasting accuracy for medicine consumption across four hospitals, measured by MAPE. The metric values exhibit a broad range, from a low of 3.80% to a high of 222.10%. Specifically, Hospital 1 demonstrates moderate forecasting accuracy, while Hospital 2 achieves the most consistent and reliable results. Hospital 3's data includes an extreme outlier that significantly affects its MAPE value, suggesting an anomaly that requires further examination. In contrast, Hospital 4 consistently experiences higher forecasting errors. The observed discrepancies in MAPE may be attributed to factors such as data volume, demand variability, case complexity, or the forecasting model's performance. This analysis is confined to the available data and does not account for external factors that could influence the results.

## 3.2 K-means clustering forecasting

Using clustering methods and forecasting the consumption of medicine in different hospitals offer several benefits. Clustering helps identify patterns and group similar data points, simplifying the complex and varied consumption behaviors of medicines. This allows for more targeted analysis and a better understanding of how different factors influence medicine usage. Forecasting, on the other hand, provides hospitals with predictive insights into future medicine needs, enabling more efficient inventory management and reducing the risk of shortages or over-
stock. Together, these techniques improve resource allocation, optimize supply chains, and support more effective and proactive healthcare planning, ultimately enhancing patient care and operational efficiency in hospitals.

Several tests were conducted using different feature combinations. The most significant results for the clustering technique were obtained using all 12 original features. One-hot encoding was applied to categorical features, and the seasonal decomposition features were excluded as they did not yield good MAPE results compared to other feature compositions. The unified dataset containing the inputs of the four hospitals was used in this experiment.

As mentioned in the previous section, since the data inputs are from different time periods, it is expected that each medicine is clustered into more than one cluster. This is because there are multiple factors to consider beyond just the medicine used itself.

<table><caption>Table 2: Table of Medicines and MAPE per Cluster using K-means</caption><thead><tr><th>Medicine</th><th>Cluster 0</th><th>Cluster 1</th><th>Cluster 2</th></tr></thead><tbody><tr><td>Medicine 1</td><td>4190%</td><td>74%</td><td>92%</td></tr><tr><td>Medicine 2</td><td>308%</td><td>159%</td><td>295%</td></tr><tr><td>Medicine 3</td><td>1021%</td><td>110%</td><td>162%</td></tr><tr><td>Medicine 4</td><td>33%</td><td>50%</td><td>33%</td></tr><tr><td>Medicine 5</td><td>4395%</td><td>62%</td><td>603%</td></tr><tr><td>Medicine 6</td><td>1786%</td><td>93%</td><td>90%</td></tr><tr><td>Medicine 7</td><td>136%</td><td>400%</td><td>66%</td></tr><tr><td>Medicine 8</td><td>323%</td><td>208%</td><td>117%</td></tr><tr><td>Medicine 9</td><td>1721%</td><td>97%</td><td>21%</td></tr><tr><td>Medicine 10</td><td>404%</td><td>39%</td><td>197%</td></tr><tr><td>Medicine 11</td><td>37500%</td><td>815%</td><td>339%</td></tr><tr><td>Medicine 12</td><td>1709%</td><td>36%</td><td>34%</td></tr><tr><td>Medicine 13</td><td>238%</td><td>300%</td><td>92%</td></tr><tr><td>Medicine 14</td><td>1491%</td><td>27%</td><td>74%</td></tr><tr><td>Medicine 15</td><td>1832%</td><td>23%</td><td>2699%</td></tr><tr><td>Medicine 16</td><td>523%</td><td>58%</td><td>541%</td></tr><tr><td>Medicine 17</td><td>197%</td><td>200%</td><td>65%</td></tr><tr><td>Medicine 18</td><td>3734%</td><td>649%</td><td>7370%</td></tr><tr><td>Medicine 19</td><td>1937%</td><td>118%</td><td>57%</td></tr><tr><td>Medicine 20</td><td>9604%</td><td>35%</td><td>21%</td></tr><tr><td>Medicine 21</td><td>1690%</td><td>170%</td><td>149%</td></tr></tbody></table>

Table 2 that shows the MAPE results from different clusters using the K-means technique shows none achieved acceptable performance. As mentioned earlier, metrics for evaluating different values of K for clustering determined that three clusters were optimal, but not the only option. Different values of K were tested, and for values greater than three, some clusters had too few data points to allow for effective forecasting, leading to their exclusion. Analyzing the cluster compositions revealed all medicines had data points distributed across
each cluster. This was expected since multiple entries from different dates with varying variables can influence cluster assignment. For example, Medicine A in month X might belong to one cluster, while the same medicine in month Y might belong to another because of seasonal effects or other factors. Accurate predictions for medicine logistics in hospitals are crucial: underestimation risks stock-outs, while overestimation impacts the facility's budget. Various cluster numbers were tested, including four clusters corresponding to the four hospitals, but this approach did not yield good metrics compared to others and was thus deemed unsuitable.

Given these results, it became clear that exploring other clustering techniques is necessary. Manual clustering emerged as a potential method to identify similarities between medicines in a straightforward manner.

### 3.3 Pair clustering forecasting using trend pattern

For this part of the work, the time series features created with seasonal decomposition were used, with the dataset with the hospitals separated, calculating individually the trends of each medicine for each hospital and then applying the manual pair clustering technique. For some hospitals there are some months without inputs and for this reason, the range of data was used from November 2017 to March 2019.

From 3486 potential medicine pair combinations, not all were considered appropriate candidates for testing and evaluating forecasting performance. Selection was therefore focused on pairs exhibiting the most similar trend patterns.

Among all the tested pairs, we selected five pairs as they represent the potential of the technique and the different combinations of medicines from the same hospital or different hospitals (Table 1). Similarities are observed based on their visual representation of the trends. Even some pair had different magnitudes, they had similar behavior. Moreover, some pairs, even that they are from different hospitals, they have common behaviors. Within this manual process, only top five pairs were selected and are presented in Table 3. The aim is to analyse each of these pairs to understand why they are grouped together.

<table><caption>Table 3: Example of Pairs of Medicines and Hospitals</caption><thead><tr><th>Cluster</th><th>Medicine A</th><th>Hospital A</th><th>Medicine B</th><th>Hospital B</th><th>MAPE A</th><th>MAPE B</th></tr></thead><tbody><tr><td>1</td><td>Medicine 3</td><td>1</td><td>Medicine 2</td><td>1</td><td><strong>3.20%</strong></td><td><strong>8.40%</strong></td></tr><tr><td>2</td><td>Medicine 15</td><td>1</td><td>Medicine 4</td><td>4</td><td><strong>3.30%</strong></td><td><strong>9.30%</strong></td></tr><tr><td>3</td><td>Medicine 15</td><td>1</td><td>Medicine 13</td><td>3</td><td><strong>2.10%</strong></td><td><strong>8.30%</strong></td></tr><tr><td>4</td><td>Medicine 20</td><td>1</td><td>Medicine 20</td><td>3</td><td><strong>1.80%</strong></td><td><strong>7.10%</strong></td></tr><tr><td>5</td><td>Medicine 9</td><td>1</td><td>Medicine 9</td><td>2</td><td><strong>8.30%</strong></td><td><strong>4.70%</strong></td></tr></tbody></table>

For the first pair in Table 3, the analysis covered the period from November 2017 to January 2019. The pronounced similarity in consumption patterns for the
two medicines (Medicine 3 and medicine 2) within the same hospital (Hosptial 1) suggests a reliable forecast. As detailed in the preceding section, the input data for these medicines was combined and processed through the forecasting pipeline. The resulting MAPE values were 3.20% for Medicine 3 and 8.40% for Medicine 2 within the test dataset, in contrast with the baseline values of 13.80% and 13.10% respectively. These outcomes may be attributed to factors such as seasonality and the demographic characteristics of the patient population at Hospital 1, which influence the consumption rates of both medicines. Figure 7 provides a visual representation of the trend for the first pair.

<figure><img src="image_8.png" /><figcaption>Fig. 7: Trends comparison between first pair</figcaption></figure>

The second pair under examination in Table 3 includes two distinct medicines from separate hospitals. Given this context, the previously considered factors of seasonality and hospital size are unlikely to be the primary influences on the observed similarities in consumption trends. It is important to note that the analysis period remains consistent with that of the first pair, spanning from November 2017 to January 2019. This uniformity ensures that the comparison across different pairs is methodologically sound. The consumption trends for this second pair, which may suggest other underlying factors such as prescribing habits, patient demographics, or even regional health policies, are depicted in Figure 8. A deeper investigation into these trends could provide valuable insights into the factors driving medicine consumption patterns across different hospital facilities.
<figure><img src="image_9.png" /><figcaption>Fig. 8: Trends comparison between second pair</figcaption></figure>

The comparative analysis of the second pair yields mixed results. For Medicine 15, the MAPE is encouraging (3.30%), markedly better than the baseline's (19.70%). This suggests that the forecasting model performs well for this medicine at Hospital 1. In contrast, Medicine 4 from Hospital 4 shows a MAPE of (9.30%), which is not as favorable, especially when compared to its baseline of (7.10%). This discrepancy shows that the model may not be as effective for this medicine, signaling a need for further investigation and potential model adjustments. Fig. 9 illustrates three other pairs of medicines with their trends.

The forecasting results for the third pair are notably impressive (Fig.9a). Medicine 15 of Hospital 1 demonstrates a MAPE of (2.10%), which is a significant improvement compared to the baseline MAPE of (19.70%). Additionally, Medicine 13 from Hospital 3 achieves a MAPE of (8.30%), also surpassing the baseline's (14.70%). These results highlight the effectiveness of the forecasting model for both medicines, with substantial enhancements over the established baselines.

The analysis of Medicine 20 presented in Fig.9b from different hospitals (1 and 3) reveals that combining the data leads to a MAPE metric that outperforms the baseline for both institutions. Specifically, for Hospital 1, the baseline MAPE is (25.40%), which is significantly higher than the (1.80%) achieved when using the paired data. Similarly, Hospital 3 shows a baseline MAPE of (15.00%), compared to (7.10%) with the paired data. These improved results from using combined data support the hypothesis that there are underlying factors contributing to the similarity in medicine consumption trends across different hospitals. Identifying these factors could be instrumental in developing more accurate combined forecasting models, which consider the shared influences on medicine consumption.

Figure 9c displays the consumption trends for Medicine 9 at hospitals 1 and 2. The forecasting results show an improvement for Hospital 1, with the MAPE decreasing from (10.00%) to (8.30%). However, Hospital 2 experienced a slight increase in MAPE from (4.00%) to (4.70%). This marginal difference at Hospital 2 raises considerations about the trade-offs involved in optimizing
<figure><img src="image_10.png" /><figcaption>Fig. 9: Comparison of trends between different pairs</figcaption></figure>

forecast accuracy for one medicine at the expense of another. It prompts a careful evaluation of whether the gains in precision for one hospital justify the minor loss in another, ensuring that the overall prediction of medicine consumption remains robust.

Many pairs were examined, yet the five showcased in this analysis were telling. They provide some comprehensive comparison between the baseline forecasts and those obtained using the paired data approach, alongside manual clustering. These examples serve to illustrate the potential benefits and challenges of integrating data across different contexts to enhance forecasting models.

The results from the K-means (and other tested clustering techniques) did not yield satisfactory outcomes, likely because of insufficient data and the inherent complexity of medicine consumption patterns. The limited dataset may not have provided enough variability to form distinct clusters effectively, leading to poor predictive performance. To address this, manual pair clustering was explored as an alternative, allowing for the identification of similarities between medicines based on domain knowledge, rather than relying solely on automated algorithms. However, this approach also has limitations, such as the focus on only pairing medicines, which might not capture the full spectrum of relationships.

Additionally, the study compared unified and separated approaches to clustering. The unified approach, which combined data from all hospitals, did not produce as good results as the separated approach, where data from each hospital were treated independently. The separated approach allowed for more tailored
clustering that better reflected the unique consumption patterns of each hospital. Based on these findings, it is recommended to investigate further manual clustering in combination with a separated approach, as this method demonstrated more accurate forecasting of medicine consumption. Future work should aim to gather more extensive and diverse datasets to enhance the clustering process and further validate these methods.

Therefore, the proposed approach is hardly applicable in reality in the current state. Additionally to the suggestions of improvements made above, It will be interesting to analyse other variables that could determine the variations in consumption.

# 4 Conclusion

Investing in medicine consumption forecasting is crucial due to its significant impact on hospital logistics costs, particularly in public hospitals with high patient demand where efficient resource allocation is critical. Although various forecasting methods have been explored in previous studies, the Random Forest Regressor has proven to be the most suitable for our dataset and context. By meticulously formatting, treating, and engineering features from the raw data, we transformed it into actionable insights. This enabled the application of clustering methods to streamline the number of forecasting models, facilitating more generalized forecasts and the potential to extend these predictions to new hospitals using existing data.

While the classical clustering technique K-means was evaluated, it did not produce satisfactory results. An alternative approach involving seasonal decomposition and focusing on consumption trends for each hospital and medicine led to the manual pairing of medicines. This approach raised a pivotal question: Does grouping medicines with similar trends inherently lead to superior forecasting outcomes? The findings from this study suggest that, in certain instances, such groupings do indeed result in improved MAPE metrics, indicating the presence of latent factors that enhance prediction accuracy. Consequently, further research is needed to uncover these factors.

Attempts to extend the clustering to include trios and quartets of medicines were also made. However, these did not yield better results for the majority of combinations tested. Given the time-intensive nature of manual clustering, it was not feasible to determine definitively whether incorporating more diverse data could yield improved outcomes.

Looking ahead, future research should consider methodologies like Dynamic Time Warping (DTW), which has demonstrated promise in clustering time series data and has garnered positive results in existing literature. Exploring DTW and other advanced techniques could provide deeper insights into the complex patterns of medicine consumption, leading to even more accurate and effective forecasting models.
Acknowledgements

This work has been partially supported by the MIAI Multidisciplinary AI Insti-
tute at the Univ. Grenoble Alpes: (MIAI@Grenoble Alpes - ANR-19-P3IA-0003).

References

1. Aptel, O., Pourjalali, H.: Improving activities and decreasing costs of logistics in hospitals: a comparison of us and french hospitals. The international journal of accounting **36**(1), 65–90 (2001)

2. Beldek, T., Konyahoğlu, A., Camgoz Akdag, H.: Supply Chain Management in Healthcare: A Literature Review, pp. 570–579. springer (08 2019)

3. Bertolotti, F., Schettini, F., Ferrario, L., Bellavia, D., Foglia, E.: A prediction framework for pharmaceutical drug consumption using short time-series. Expert Systems with Applications **253**, 124265 (2024)

4. Cateau, D., Bugnon, O., Niquille, A.: Evolution of potentially inappropriate med-
ication use in nursing homes: retrospective analysis of drug consumption data.
Research in Social and Administrative Pharmacy **17**(4), 701–706 (2021)

5. Chicco, D., Warrens, M.J., Jurman, G.: The coefficient of determination r-squared is more informative than smape, mae, mape, mse and rmse in regression analysis evaluation. Peerj computer science **7**, e623 (2021)

6. Fu, W., Simonoff, J.S.: Unbiased regression trees for longitudinal and clustered data. Computational Statistics & Data Analysis **88**, 53–74 (2015)

7. Ghousi, R., Mehrani, S., Momeni, M., Anjomshoaa, S.: Application of data mining techniques in drug consumption forecasting to help pharmaceutical industry production planning. In: Proceedings of the 2012 international conference on industrial engineering and operations management. pp. 3–6 (2012)

8. Hajjem, A., Bellavance, F., Larocque, D.: Mixed effects regression trees for clustered data. Statistics & Probability Letters **81**(4), 451–459 (2011)

9. Hamzehlou, M.: System dynamics model for an agile pharmaceutical supply chain during covid-19 pandemic in iran. PloS one **19**, e0290789 (01 2024)

10. Jimenez, F., Palma, J., Sanchez, G., Marin, D., Palacios, M.F., López, M.L.: Feature selection based multivariate time series forecasting: An application to antibiotic resistance outbreaks prediction. Artificial Intelligence in Medicine **104**, 101818 (2020)

11. Koala, D., Yahouni, Z., Alpan, G., Si Mohand, D.: Correlation analysis of factors impacting health product consumption in French hospitals. IFAC-PapersOnLine **55**(10), 895–900 (2022)

12. Koala, D., Yahouni, Z., Alpan, G., Frein, Y.: Factors influencing drug consumption and prediction methods. In: CIGI-Qualita : International conference on industrial Engineering, Grenoble (2021)

13. Lim, S.S.Y., Phouratsamay, S.L., Yahouni, Z., Gascard, E.: Medicine consumption demand forecasting in french hospitals using seasonal auto-regressive integrated moving avrage (sarima) models. In: 8th International Conference on Control, Automation and Diagnosis (ICCAD’24), Paris, France (2024)

14. M. Zied Babai, J.E.B., Rostami-Tabar, B.: Demand forecasting in supply chains: a review of aggregation and hierarchical approaches. International Journal of Production Research **60**(1), 324–348 (2022)
15. Mizan, T., Taghipour, S.: Medical resource allocation planning by integrating machine learning and optimization models. Artificial Intelligence in Medicine **134**, 102430 (2022)

16. Mousa, B.A., Al-Khateeb, B.: Predicting medicine demand using deep learning techniques: A review. Journal of Intelligent Systems **32**(1), 20220297 (2023)

17. OCDE: Health at a Glance 2013: OECD Indicators. OECD Publishing (2013)

18. Ramirez-Alcocer, U.M., Hernandez-Resendiz, J.D., Leal, E.T.: Evaluation of deep learning network architectures for medicine expenditure prediction in the healthcare domain. In: Applied Intelligence for Medical Image Analysis, pp. 179–199. Apple Academic Press (2024)

19. Speiser, J.L.: A random forest method with feature selection for developing medical prediction models with clustered and longitudinal data. Journal of Biomedical Informatics **117**, 103763 (2021)

20. Uthayakumar, R., Priyan, S.: Pharmaceutical supply chain and inventory management strategies: Optimization for a pharmaceutical company and a hospital. Operations Research for Health Care **2**(3), 52–64 (2013)

21. Volland, J., Fügener, A., Schoenfelder, J., Brunner, J.O.: Material logistics in hospitals: A literature review. Omega **69**, 82–101 (2017)

22. Vélez, D., Phouratsamay, S.L., Yahouni, Z., Alpan, G.: Predicting medicine demand fluctuations through markov chain. In: 12th International Workshop on Service Oriented, Holonic and Multi-Agent Manufacturing Systems for Industry of the Future. pp. 329–340. Bucharest, Romania (Sep 2022)

23. Wang, X., Smith, K., Hyndman, R.: Characteristic-based clustering for time series data. Data mining and knowledge Discovery **13**, 335–364 (2006)