Data Science And Analytics For Operations
November 06, 2026
Sales Forecasting with Machine Learning Based on Climate Variables in an Ice Cream Shop on the Paulista Coast
Ellen Miyuki Miyashima; João Vitor Rego Muniz
DOI: 10.22167/2675-6528-202603646
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 ice cream sector in Brazil, characterized by high sales seasonality and sensitivity to climatic and tourist factors, presented critical challenges in inventory management. The study analyzed the historical sales behavior of two franchised ice cream units in Ubatuba, on the northern coast of São Paulo. The objective was to apply predictive demand models capable of estimating sales volume approximately one month in advance, combining historical sales data, climatic information obtained via OpenWeatherMap API, and holiday data, processed in Python. Exploratory analysis revealed a positive correlation of 0.70 between average temperature and daily sales in the consolidated period, which reached 0.76 in 2025, and a progressive inhibitory effect of precipitation on sales, consistent over the three years analyzed. Three supervised machine learning models were trained and compared. XGBoost was selected as the best-performing model, with an R² of 0.6636 under operational conditions and 0.6255 during peak season. The model delivered daily volume predictions by product category, directly applicable to purchasing planning and inventory sizing.
Keywords: Data analysis; Food franchises; Inventory management; Predictive modeling; Time series.
1. Introduction
The ice cream and gelato sector in Brazil holds a position of growing economic relevance in the national market. According to the Brazilian Association of Ice Cream Industries and Sector (ABIS, 2025), the country has over 11,000 companies linked to the segment, with an annual revenue exceeding R$ 14 billion and an average growth of 15% per year. This boost stems from both product innovations and the increase in global average temperatures and their consequent effect on demand. Approximately 52% of the total national consumption is concentrated in the Southeast region, which corresponds to the geographical context of the present study.
Consumer behavior in this sector is strongly influenced by climatic and tourist factors. Research by ABRASORVETE in partnership with EJFGV (2024) reveals a per capita consumption of 7.7 liters of ice cream per year in Brazil, with 66.53% of consumers being influenced by the weather at the time of purchase. This data reinforces the sector’s strong seasonality, where 60% to 70% of sales are concentrated in the summer period, as already pointed out by ABIS (2025). Analogous behavior is observed in other tropical countries, with Euromonitor (2023) identifying consumption peaks in Mexico and Thailand. The Institute for Retail Development (IDV, 2023) records increases of 10% to 25% in sales in tourist regions during periods of higher traffic. Studies by SEBRAE (2021) and Silva and Almeida (2021) indicate that temperature increases above the weekly average result in immediate increments in the demand for frozen products.
In this scenario, inventory management is configured as a critical operational factor for ice cream shops, especially because it involves highly perishable products that require strict conservation conditions. Ballou (2006) and Chopra and Meindl (2016) point out that the use of historical sales data makes it possible to anticipate needs, reduce shortages and excesses, and align inventory with real demand. Corrêa and Corrêa (2012) reinforce that data-supported decisions make planning more reliable. Dang, Feng, and Chen (2020) add that, for temperature-sensitive products like ice cream, management complexity increases considerably, and inadequate replenishment can amplify operational costs and risks.
The preliminary analysis of historical sales data from the two investigated units revealed a positive correlation of 0.70 between average temperature and daily sales volume in the consolidated period from 2023 to 2025. This correlation rose to 0.76 when isolating the year 2025, evidencing a growing alignment between climatic conditions and consumer purchasing behavior. Additionally, a negative correlation of -0.09 was observed between precipitation and sales. The analysis by rainfall intensity demonstrated that days with moderate and heavy precipitation are systematically associated with significant reductions in sales volume compared to dry days, a consistent pattern over the three years analyzed. These findings reinforce the relevance of including climatic variables in predictive models for inventory planning in the segment.
Given this context, the present work is justified by the need to improve the efficiency of purchasing planning in ice cream franchises located in regions with high seasonality and strong tourist appeal. The application of predictive demand models, incorporating variables such as temperature, precipitation, holidays, days of the week, and tourist flow, represents a concrete alternative to reduce losses due to excess or lack of stock, optimizing the operational results of the studied units, located in Ubatuba, on the north coast of the state of São Paulo. Therefore, the present work aimed to analyze the historical sales behavior of the studied units and to develop and compare supervised machine learning models, based on climatic, calendar, and historical behavior variables, capable of estimating sales volume approximately one month in advance.
2. Material and Methods
Research Characterization
The research is experimental in nature, with a quantitative approach and applied purposes, conducted in two units of a small artisanal ice cream shop in Ubatuba, on the northern coast of São Paulo. The establishments operate in a context of seasonal tourist flow, with variable demand between high and low seasons. The objective was to develop and validate sales predictive models, using climatic, calendar, and historical behavior variables, to optimize inventory management and operational decisions.
Data Source and Collection
The database was composed of three integrated sources. The first included historical daily sales records from the two units (Unit 1 – Centro and Unit 2 – Perequê-Açu), extracted from the internal management system, from May 2023 to March 2026. These data contained quantity sold, value, and product category, excluding non-ice cream categories (e.g., water, styrofoam, bags). A future 30-day period (March 11 to April 9, 2026) was included, with filled weather and calendar variables, for the generation of operational forecasts. The second source was historical weather data from Ubatuba (minimum, average, and maximum temperature; daily precipitation), collected via the OpenWeatherMap OneCall 3.0 API. A hierarchical fallback strategy (reprocessing via API, consultation with the Meteostat library, and triangulation with Caraguatatuba) was used for days without valid data, and the NASA POWER API validated the rainfall accumulations. The third source consisted of a structured calendar of holidays (national, state, and municipal) and commemorative dates, incorporated as binary variables (e.g., is_holiday, is_weekend).
Data Treatment and Integration
Data processing was performed in Python, in the Google Colaboratory environment, using the libraries Pandas (v2.2.2), NumPy (v1.26.4), Requests, and Meteostat (v1.6.5). The three sources were integrated into a single analytical DataFrame, using ‘data_registro’ as the key. Failures in temperature collection (minimum equal to maximum) were handled with the hierarchical recovery protocol. Precipitation was categorized into five ordinal intensity classes: Dry (≤ 0.5 mm), Light (0.5 to 10.0 mm), Moderate (10.0 to 25.0 mm), Heavy (25.0 to 50.0 mm), and Very Heavy (> 50.0 mm). After consolidation, the climatic values were propagated by broadcast to all transactional rows of the same day.
Exploratory Data Analysis
Exploratory analysis was performed with Matplotlib, Seaborn, and Scikit-learn, using daily transaction clustering as the unit of observation. Pearson correlation coefficients were calculated between sales volume and average temperature and accumulated precipitation, stratified by year and in an aggregated manner. The impact of rain was evaluated by category (dry vs. rainy) and by rainfall intensity. Heterogeneity between units was investigated by comparing average volumes, rain sensitivity, and individualized temperature-sales correlation. A monthly time series (May 2023 to December 2025) was constructed to identify seasonal patterns and peak season spikes. The relative importance of variables (temperature, precipitation, binary rain, weekend, and holiday) was quantified using Random Forest Regressor (100 estimators, random_state=42), in a consolidated manner and per unit.
Predictive Modeling
Three sales forecasting models based on supervised machine learning were developed and compared: Random Forest Regressor (Breiman, 2001), XGBoost Regressor (Chen; Guestrin, 2016), and LightGBM Regressor. The models were trained on a historical series of 998 days of aggregated daily sales from the two units, from June 2023 to March 2026. The 18 predictor variables included climate data (minimum, average, and maximum temperature, precipitation, rainfall intensity), calendar data (holiday, weekend, month, day of the week, high season indicator), and historical behavior data (7, 14, and 28-day lags and 7 and 14-day moving averages). The response variable was the total daily quantity of products sold per unit.
The Random Forest Regressor was implemented via Scikit-learn (100 estimators, random_state=42). The XGBoost Regressor was configured with n_estimators=100, learning_rate=0.1, max_depth=6, and random_state=42. The LightGBM Regressor uses gradient boosting with vertical tree growth. The models were evaluated by MAE, RMSE, and R².
Predictive Modeling: Performance Analysis and Model Limitations
To evaluate the predictive performance, two distinct temporal split test scenarios were defined: Test A and Test B. Test A (operational everyday) used data from May 2023 to September 2025 for training and October to December 2025 (92 days) for testing, representing low to moderate demand. Test B (high season) trained with data from May 2023 to December 2025 and tested with January to March 2026 (69 days), covering the peak demand driven by tourism and Carnival. The separation into two scenarios allowed for a more precise evaluation of the model’s performance in different demand contexts, providing quantified insights for routine and peak stock decisions.
3. Results and Discussion
Exploratory Data Analysis
The exploratory analysis of the historical dataset, covering the period from May 2023 to March 2026, revealed consistent patterns of association between climatic variables and the daily sales volume of the two units investigated. Pearson correlation coefficients calculated for the consolidated period indicated a positive correlation of 0.70 between average temperature and quantity sold, and a negative correlation of 0.09 between precipitation and sales. When isolating the year 2025, the correlation between temperature and sales rose to 0.76, suggesting a growing alignment between thermal conditions and purchasing behavior over the sample period, as illustrated in Figure 1.
Figure 1. Correlation between Average Temperature and Daily Sales.

Source: Original research results
The unit analysis revealed individual coefficients of 0.67 for Unit 1 – Centro and 0.66 for Unit 2 – Perequê-Açu, indicating stability in the relationship between the two points of sale. The segmentation by rainfall intensity showed progressive reductions in average daily sales as precipitation volume increased, a pattern consistently observed over the three years analyzed. Days with moderate and heavy rain registered significant drops in sales volume compared to dry days, while days with light rain showed variable behavior between years, according to Figure 2.
Figure 2. Average Daily Sales by Rainfall Intensity and Year.

Source: Original research results
The analysis of the category mix indicated that Fruits, Farm, and Delight jointly accounted for the largest share of sales in both units, with seasonal variations in relative participation over the months, as illustrated in Figure 3 and Figure 4. Daily average rankings by day profile showed approximately 50% increases in sales on weekends compared to weekdays, with additional rises on holidays for the main categories.
Figure 3. Monthly Evolution of Sales by Unit and Average Temperature.

Source: Original research results
Figure 4. Category Mix: Participation in Total Sales Volume (May/2023 – Mar/2026).

Source: Original research results
Predictive Modeling
The predictive modeling process was conducted with three ensemble-based decision tree machine learning algorithms: Random Forest, XGBoost, and LightGBM. The models were trained on a historical series of 998 days of aggregated daily sales from the two units, from June 2023 to March 2026. The series presented an average of 1,598 units sold per day, with a minimum of 47 and a maximum of 6,991 units, evidencing the high variability characteristic of a business with intense tourist seasonality. The features used included climatic variables (minimum, average, and maximum temperature, precipitation, rainfall intensity), calendar variables (holiday, weekend, month, day of the week, high season indicator), and historical behavior variables (7, 14, and 28-day lags and 7 and 14-day moving averages), totaling 18 predictors. The evaluation was performed in two distinct test scenarios to separate performance in daily operations from extreme high season peaks.
In Test A, referring to operational daily operations (October to December 2025), with 92 days of evaluation and training out of 837 days, XGBoost showed the best performance among the models, with an R² of 0.6636, an MAE of 656.6 units, an RMSE of 899.0 units, and a MAPE of 31.25%. LightGBM achieved close results, with a MAPE of 29.40%, the lowest among all models in both scenarios, and an R² of 0.5579. Random Forest registered an R² of 0.5227. XGBoost was the only model to achieve an R² above 0.66, explaining approximately two-thirds of the daily sales variance in a period without the influence of extreme tourist peaks.
In Test B, which evaluated the peak season (January to March 2026), with 69 days of evaluation and training over 929 days, the average daily sales volume in the test period was 2,906 units, with a minimum of 251 and a maximum of 6,991 units per day, reflecting the intensity and volatility characteristic of the period. XGBoost maintained its performance lead, with an R² of 0.6255, MAE of 813.0 units, RMSE of 1,045.6, and MAPE of 35.76%. Random Forest achieved an R² of 0.5933 and a MAPE of 40.45%, while LightGBM recorded an R² of 0.5904 and a MAPE of 39.98%. The performance degradation compared to Test A was 6.4 percentage points in the MAPE of the best model (from 29.40% to 35.76%), which quantifies the impact of extreme seasonality on predictive accuracy. This difference is explained by the reduced number of examples from the peak period in the training set, the absence of external tourist flow variables, and the movable date nature of Carnival, which introduces a peak that is difficult to capture by models based exclusively on fixed date features.
Based on the comparative results, XGBoost was selected as the final model for generating operational forecasts, as it presented the best R² in both test scenarios. Applied to the 30 future days present in the dataset, from March 11 to April 9, 2026, the model generated iterative forecasts with lag propagation and breakdown by product category, as illustrated in Figure 5. The total volume predicted for the period was 34,199 units, distributed among 33 categories. The three categories with the highest predicted share were Fruits (16.7% of the total, 5,721 units), Farm (15.6%, 5,351 units), and Delícia (14.4%, 4,931 units), which together represented 46.7% of the total predicted volume. The Sensa Picolé (8.2%), Festa ao Leite (7.4%), and Hello Kitty e Amigos (5.4%) categories completed the top six, accounting for 67.7% of the total predicted. The remaining 27 categories divided the remaining 32.3%, with individual shares between 0.0% and 4.5%, reflecting the natural fragmentation of the portfolio into categories with lower turnover.
Figure 5. Sales Forecast by Category – March 11 to April 9, 2026.

Source: Original research results
The replicability of the approach deserves special mention, as the availability of free and open-source climate APIs, combined with existing internal sales records in management systems, makes the method accessible to other establishments in the segment without the need for complex technological infrastructure. This represents a concrete alternative for small businesses in the out-of-home food sector operating in contexts of high seasonality. As limitations of the study, the geographical restriction of the sample to two units of a single franchised chain in Ubatuba should be highlighted, which may limit the generalization of the results to other operational contexts. Furthermore, the absence of variables related to non-recurring local events, such as concerts, festivals, and hotel occupancy, which possibly influence tourist demand, was not captured by the model.
In summary, the exploratory analysis confirmed statistically relevant associations between climatic conditions and daily sales volume, with average temperature and precipitation significantly influencing demand. The XGBoost model demonstrated the best predictive performance in everyday operational and high season scenarios, providing daily volume forecasts by product category. These findings indicate that climatic, calendar, and historical behavior variables can support predictive demand models for purchasing planning and inventory management, even with the limitations observed in periods of extreme seasonality.
4. Conclusion
This study analyzed the historical sales behavior of two ice cream franchise units in Ubatuba and developed demand predictive models to estimate sales volume approximately one month in advance, incorporating climatic, calendar, and historical behavior variables. A positive correlation of 0.70 was found between average temperature and daily sales, which increased to 0.76 in 2025, and a progressive inhibitory effect of precipitation on sales volume, consistent throughout the three years analyzed. It was observed that weekends and holidays boost sales by approximately 50% compared to weekdays, and the Fruit, Farm, and Delight categories concentrate the largest portion of the volume. Among the trained supervised machine learning models, XGBoost demonstrated the best performance, with an R² of 0.6636 under operational conditions and 0.6255 during high season, providing daily volume forecasts by product category. The main contribution lies in the replicability of the approach, which, by combining internal sales data with climate information from free APIs, offers an accessible and concrete tool for purchase planning and inventory management in small food sector businesses in regions with high seasonality.
However, the study presented important limitations, such as the geographical restriction of the sample to two units of a single franchised chain in Ubatuba, which may affect the generalization of the results to other operational contexts. Additionally, the absence of variables related to non-recurring local events, such as shows and festivals, and hotel occupancy, which influence tourist demand, was not captured by the model. The degradation of predictive performance during periods of extreme high seasonality, such as Carnival, was attributed to the scarcity of peak examples in the training set and the mobile date nature of some events. It is suggested that future studies incorporate these tourist flow and local event variables, as well as expand the geographical scope to other coastal regions or segments of the food industry with similar demand patterns, in order to improve the accuracy and applicability of the models.
Bibliographic References
Abrasorvete; Ejfgv. 2024. Pesquisa com o consumidor: consumo per capita no Brasil, volume e crescimento do setor de sorvetes. Disponível em: https://abrasorvete.com.br. Acesso em: 27 nov. 2025.
Associação Brasileira das Indústrias e do Setor de Sorvetes [ABIS]. 2025. Informações institucionais e dados gerais do setor. Disponível em: http://www.abis.com.br. Acesso em: 27 nov. 2025.
Ballou, R.H. 2006. Logística empresarial: transporte, administração de materiais e distribuição física. Pearson/Atlas, São Paulo, SP, Brasil.
Breiman, L. 2001. Random forests. Machine Learning 45(1): 5-32.
Chen, T.; Guestrin, C. 2016. XGBoost: a scalable tree boosting system. In: ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 22, 2016, New York, NY, EUA. Anais… p. 785-794.
Chopra, S.; Meindl, P. 2016. Gestão da cadeia de suprimentos: estratégia, planejamento e operação. 6ed. Pearson, São Paulo, SP, Brasil.
Corrêa, H.L.; Corrêa, C.A. 2012. Administração da produção e operações: manufatura e serviços: uma abordagem estratégica. 3ed. Atlas, São Paulo, SP, Brasil.
Dang, Q.; Feng, Y.; Chen, Z. 2020. Cold supply chain logistics: demand forecasting and inventory management of temperature-sensitive products. International Journal of Production Economics 227: 107-116.
Euromonitor International. 2023. Ice cream in Brazil 2023. Disponível em: https://www.euromonitor.com. Acesso em: 27 nov. 2025.
Instituto para Desenvolvimento do Varejo [IDV]. 2023. Relatórios de desempenho do varejo e sazonalidade de consumo. Disponível em: https://www.idv.org.br. Acesso em: 27 nov. 2025.
Sebrae. 2021. Estudo de mercado: sorveterias e sobremesas geladas. Sebrae, Brasília, DF, Brasil.
Silva, J.P.; Almeida, R.F. 2021. Influência de variáveis climáticas na demanda de alimentos gelados no varejo. Ciência e Agrotecnologia 45(3): 1-10.
Article originating from the Final Course Work of the Specialization in Data Science and Analytics for Operations of POLI USP PRO
To learn more about the course, click here.