ENERGY CONSUMPTION PATTERNS ANALYSIS Prediction and 24-Hour Forecasting Using Machine Learning
I. INTRODUCTION
Electricity is one of the most essential resources in modern society and is used in homes, offices, industries and educational institutions. The demand for electrical energy keeps increasing because of population growth, urbanization, industrial development and the wider use of electrical appliances. Understanding and managing electricity consumption has therefore become important for improving energy efficiency and reducing unnecessary use.
Consumption does not remain constant. It rises in the morning and evening hours when lighting, fans, air conditioners and other appliances are in use, falls during the night, differs between weekdays and weekends, and changes with the season. Temperature, humidity, the time of day, the day of the week and the season are the main factors involved. Traditional analysis based on manually checking historical records becomes difficult when the data contains a large number of hourly readings, and repeated patterns, peak periods and relations between factors are easily missed. Automated data analysis and machine learning are well suited to this task.
This paper presents Energy Consumption Patterns Analysis, a Python-based system that studies hourly electricity consumption, identifies usage patterns and predicts future requirements. The objectives are: (i) to clean the data and prepare time-based, lag and rolling-average features; (ii) to find usage patterns, peak hours and trends; (iii) to build and compare Linear Regression, Decision Tree and Random Forest models; (iv) to predict consumption and generate a 24-hour forecast; and (v) to present the analysis, prediction and forecast through a web application. Real-time smart-meter data collection and energy-wastage detection are outside the scope of the present work.
II. LITERATURE REVIEW
Several studies relate energy consumption to weather and historical load. Qiao et al. [1] predicted building energy consumption from meteorological data such as temperature and humidity using Decision Tree, Support Vector Machine, Random Forest and voting regression, and stressed the importance of feature selection and of comparing algorithms. Smith et al. [2] forecast short-term residential load from smart-meter data using customer segmentation, feature extraction and neural networks, and reported an improvement of up to 12% in hourly one-day forecasting in this work-in-progress study. Li et al. [3] grouped load records with K- means clustering, using weighted meteorological factors and historical load, and used Random Forest to select a forecasting model for each condition; the approach gave lower MAE, RMSE and MAPE than the individual models. Chahbi et al. [4] applied machine learning to energy prediction in industrial buildings in the stee l industry and used permutation feature importance to make the model easier to interpret.
Deep-learning and time-series methods have also been widely applied. Nutakki et al. [5] used LSTM and Deep Neural Network models for a seven-day forecast in a home energy management system, and Abraham et al. [6] compared LSTM and CNN models on fourteen years of hourly data from an open-source Kaggle dataset. Koduru et al. [7] reviewed ARIMA, SARIMA, Uni-LSTM and Multi-LSTM models together with anomaly detection for household consumption, and found Multi-LSTM to perform best. Dang et al. [8] compared Random Forest, XGBoost, LSTM and GRU for appliance-level hour-ahead and day-ahead forecasting, Ahmed et al. [9] compared LSTM and XGBoost on one year of per -minute household data, and Pradeep et al. [10] evaluated LSTM, BiLSTM, GRU and BiGRU on ten years of university -campus data, where a historical window of six observations performed better in most of the tested combinations.
The surveyed work shows that previous consumption and weather information are valuable inputs and that Random Forest is a strong candidate for energy prediction. However, deep-learning models may need large amounts of data, longer training time and more computing resources, and some existing systems give only a prediction without detailed pattern analysis or a simple user interface. The present work uses lightweight machine-learning models with lag features and combines data visualisation, prediction and a 24-hour forecast in a single web application.
III. PROPOSED METHODOLOGY
The system works in eight stages: data collection, preprocessing, feature extraction, exploratory data analysis (EDA), model training, prediction, 24-hour forecasting and presentation through a web application. The overall flow is shown in Fig. 1. The models are trained once offline, and the saved model and scaler are then loaded by the application for every prediction request.

A. Dataset
The input is a CSV file (energy.csv) of 17,544 hourly records from January 2023 to December 2024. Each record holds the date and time, the electricity consumption in kWh (consumption_kwh), the temperature in °C and the humidity in %. The dataset contains generated sample values and does not represent live smart-meter readings.
B. Data Preprocessing
The datetime column is converted to the date-time type and the records are arranged in chronological order. Duplicate rows are removed, and missing consumption values are filled with the average consumption of the same hour of the day.
C. Feature Engineering
Three groups of features are derived. Time features are the hour, day of the week, month, year, quarter, week and day. Indicator features mark weekends and peak hours. Previous-usage features are the consumption one hour earlier (lag_1h), the consumption 24 hours earlier (lag_24h) and the rolling mean of the last 24 hours (rolling_mean_24h). The first 24 rows have no previous-usage values and are dropped, which leaves 17,520 records for modelling.
D. Data Splitting and Scaling
Because the data is a time series, it is split chronologically without shuffling into 80% training and 20% testing data. A StandardScaler is fitted on the training features only and then applied to both the training and the test features.
E. Machine-Learning Models
Three regression models are trained on the scaled training data. Linear Regression is used as a simple baseline. Decision Tree learns a set of rules that split the data on the input features. Random Forest combines many decision trees, which helps it capture non-linear relations between the features and the consumption.
F. Evaluation Metrics
The models are compared on the test data using the Mean Absolute Error (MAE), the Root Mean Squared Error (RMSE) and the R² score, where yi is the actual consumption, ŷi the predicted consumption, ȳ the mean of the actual values and n the number of test records:
MAE = (1/n) ∑i=1n | yi − ŷi | (1)
RMSE = √[(1/n) ∑i=1n (yi − ŷi)2 ] (2)
R2 = 1 − [∑i=1n (yi − ŷi)2 ] / [∑i=1n (yi − ȳ)2 ] (3)
G. Prediction, Forecast and Web Application
The best model and its scaler are saved with Joblib (energy_model.pkl and scaler.pkl) and loaded once when the application starts. For a prediction, the user enters the temperature, humidity, hour, day of the week, month and the previous -hour and previous-day consumption; each value is checked against its allowed range (for example, the temperature must be between −10 and 50 °C). The remaining features are derived from the inputs, scaled, and passed to the model, and the predicted consumption in kWh is classified as low, moderate or high, together with a peak or off -peak status. For the 24-hour forecast, the next 24 hourly time stamps are created with assumed temperature and humidity values; each hourly prediction is used as the previous-hour value for the next hour, and the total, maximum, minimum and average values are calculated.
The system is implemented in Python on Windows using Pandas and NumPy for data handling, Scikit-learn for the models, Matplotlib and Seaborn for the charts, and the built-in http.server module for the web application. An Intel Core i3/i5 or higher processor with at least 4 GB of RAM (8 GB recommended) is sufficient to run it.
IV. RESULTS AND DISCUSSION
A. Exploratory Data Analysis
The hourly pattern is shown in Fig. 2. The highest average consumption occurs at 19:00 (381.40 kWh) and the lowest at 01:00 (220.37 kWh), with higher usage in the morning and evening periods and lower usage late at night and in the early morning.

Fig. 3 shows the monthly pattern. June has the highest monthly average (365.26 kWh) and November the lowest (250.22 kWh). Across the days of the week, weekend consumption is higher than weekday consumption in this dataset: Sunday records the highest average (323.57 kWh) and Wednesday the lowest (292.00 kWh).

The seasonal comparison in Fig. 4 shows the highest average consumption in summer (36 3.33 kWh), followed by winter (330.96 kWh) and autumn (253.56 kWh). The higher summer consumption may be associated with the use of cooling appliances such as fans and air conditioners. The main findings are summarised in Table I.

| Pattern | Highest average | Lowest average |
|---|---|---|
| Hour of the day | 19:00 (381.40 kWh) | 01:00 (220.37 kWh) |
| Month | June (365.26 kWh) | November (250.22 kWh) |
| Day of the week | Sunday (323.57 kWh) | Wednesday (292.00 kWh) |
| Season | Summer (363.33 kWh) | Autumn (253.56 kWh) |
The relation between temperature and consumption is weak, with a correlation of about 0.14, so temperature alone cannot explain the changes in consumption and is used together with the other features. The correlation heatmap in Fig. 5 shows that previous usage is much more strongly related to current consumption: lag_24h has a correlation of 0.92, lag_1h 0.83 and rolling_mean_24h 0.62. This supports the use of the lag and rolling-mean features in the models.

B. Model Performance
Table II gives the MAE, RMSE and R² score of the three models on the test data. Random Forest is the best model: it has the lowest MAE and RMSE and the highest R² score (0.9385), with the Decision Tree close behind. Linear Regression has a negative R² score (−2.1523), which means that on the test data it fits worse than simply predicting the mean consumption, so a linear model is not suitable for this data.
| Model | MAE (kWh) | RMSE (kWh) | R² score |
|---|---|---|---|
| Linear Regression | 32.9517 | 131.0470 | −2.1523 |
| Decision Tree | 14.5977 | 20.1892 | 0.9252 |
| Random Forest | 13.5727 | 18.3017 | 0.9385 |
C. Application Output and 24-Hour Forecast
For a sample input, the application predicts a consumption of 243.66 kWh, which is classified as moderate consumption, and also shows whether the selected hour is a peak or off-peak hour and whether the day is a weekday or weekend. The 24-hour forecast screen (Fig. 6) gives a total forecast consumption of 8226.70 kWh, a maximum of 409.40 kWh at 20:00, a minimum of 294.60 kWh at 11:00 and an average of 342.80 kWh, with the hourly values shown as a bar chart and in a table.

D. System Testing
Twelve test cases were run: six functional and six non-functional. They covered dataset loading, duplicate and missing-value handling, feature generation, model training and evaluation, model loading and prediction, invalid-input handling, processing of the full dataset, response time for prediction and forecast, repeatability of results, stability under repeated use, and display in a web browser. All twelve test cases passed.
E. Limitations
The dataset contains generated sample values, so the patterns found, such as higher weekend consumption, describe this dataset and may not hold for an actual household or building. The models were evaluated on a single chronological split, and the 24-hour forecast uses assumed temperature and humidity values.
V. CONCLUSION AND FUTURE SCOPE
A system for analysing and predicting electricity consumption was developed and tested. The hourly data was cleaned and extended with time, lag and rolling-average features, and the exploratory analysis brought out the hourly, weekly, monthly and seasonal patterns and the peak hours. Among Linear Regression, Decision Tree and Random Forest, Random Forest performed best (R² = 0.9385, MAE = 13.5727 kWh, RMSE = 18.3017 kWh). A Python web application uses th e saved model to predict consumption, classify it as low, moderate or high, and generate a 24-hour forecast on an ordinary computer.
In future work, the system can be connected to smart meters and IoT devices for real-time monitoring, use a weather API for live temperature and humidity, and be extended with models such as LSTM and XGBoost. Explainable-AI techniques such as SHAP, a mobile application, energy-saving recommendations and an alert system for consumption above a set limit are also planned.
ACKNOWLEDGMENT
The authors thank Mrs. Sowmyashree S M (project co-ordinator), Mrs. Shylaja L N (Head of the Department of Artificial Intelligence and Machine Learning) and Dr. Sunil Kumar D (Principal), Bahubali College of Engineering, Shravanabelagola, for their support during this work.
REFERENCES
- Q. Qiao, A. Yunusa-Kaltungo and R. Edwards, “Predicting building energy consumption based on meteorological data,” in Proc. 2020 IEEE PES/IAS PowerAfrica Conf., Nairobi, Kenya, 2020, pp. 1–5.
- D. Smith, K. Jaskie, J. Cadigan, J. Marvin and A. Spanias, “Machine learning for fast short-term energy load forecasting,” in Proc. 2020 IEEE Conf. on Industrial Cyberphysical Systems (ICPS), Tampere, Finland, 2020, pp. 433–436.
- Z. Li, J. Zhang, W. Jing, Z. Lu, W. Zheng and X. Wen, “A short-term load forecasting method via model selection based on random forest,” 2022.
- I. Chahbi, N. Ben Rabah and I. Ben Tekaya, “Towards an efficient and interpretable machine learning approach for energy prediction in industrial buildings: A case study in the steel industry,” in Proc. AICCSA, 2022.
- M. Nutakki, M. Subashini and S. Mandava, “Energy consumption forecasting in home energy management system using deep learning techniques,” 2022.
- A. V. Abraham, P. Sasidharan, S. J. S. Tejas, M. S. Manohara, R. Muthu and R. C. Naidu, “Predicting energy consumption using LSTM and CNN deep learning algorithm,” 2022.
- S. S. Koduru, V. S. P. Machina and S. Madichetty, “A review on forecasting models and anomaly detection for hous ehold energy consumption,” 2022.
- H.-A. Dang, M. Guenana, V. B. Dinh, T. Neu and D. Guyomarc’h, “Deep learning and ensemble learning models for individual appliance level short-term load forecasting in buildings,” 2023.
- F. Ahmed, A. Arshad and A. U. Rehman, “Comparative analysis of time series forecasting of a household load consumption with LSTM neural networks and XGBoost model,” 2024.
- B. Pradeep, P. Kulkarni, F. Ullah and A. Lakas, “Energy use and demand prediction using time-series deep learning forecasting techniques: Application for a university campus,” IEEE Open J. Comput. Soc., vol. 6, pp. 189–198, 2025.