Abstract This paper presents a novel approach for ultra-short-term forecasting of electric vehicle (EV) charging loads by integrating scenario-based analysis with an improved Transformer-long short-term memory (TransLSTM) model. The objective is to enhance prediction accuracy by capturing spatiotemporal characteristics of EV charging behavior. We first use the K-means clustering algorithm to categorize charging scenarios based on EV users’ travel habits and charging data. Then, a TransLSTM model is developed to leverage the self-attention mechanism of Transformer for feature interaction and LSTM for temporal dependency modeling. Experimental results on real-world data from Shijiazhuang validate the effectiveness of the proposed method, demonstrating superior performance compared to traditional LSTM and Transformer models.

Keywords: electric vehicle; charging load forecasting; clustering analysis; Transformer; LSTM; scenario-based modeling
1. Introduction
The proliferation of electric vehicles (EVs) has become a pivotal strategy for addressing global energy and environmental challenges. As EV adoption grows, accurate forecasting of their charging loads is critical for power grid stability, resource optimization, and integration of renewable energy sources. Ultra-short-term forecasting, in particular, is essential for real-time grid dispatch and responsiveness to dynamic charging demands.
Existing methods for EV charging load forecasting can be broadly categorized into statistical spatiotemporal distribution models and machine learning (ML)-based approaches. Statistical methods, while effective in modeling complex interactions between traffic flow, charging infrastructure, and user behavior, often struggle with short-term prediction accuracy. ML-based methods, such as LSTM and Transformer, have shown promise in capturing temporal patterns, but they face challenges in handling multi-dimensional features and long-range dependencies simultaneously.
In this study, we propose a hybrid approach that combines scenario-based analysis with an improved TransLSTM model. By clustering charging data into distinct scenarios (e.g., residential, workplace, high-traffic areas), we tailor forecasting models to specific behavioral patterns. The TransLSTM model integrates the self-attention mechanism of Transformer to capture cross-dimensional feature relationships and LSTM to model temporal dynamics, thereby enhancing prediction precision across different time scales.
2. Scenario-based Analysis Using Clustering
2.1 K-means Clustering Algorithm
Clustering is a fundamental step in our framework to identify homogeneous charging patterns. The K-means algorithm is chosen for its simplicity and efficiency in partitioning data into K clusters by minimizing the within-cluster sum of squared distances:
\(J(c, \mu) = \sum_{i=1}^{n} \left\| x_i – \mu_{c_i} \right\|^2\)
where \(x_i\) is the data point, \(c_i\) is the cluster index for \(x_i\), and \(\mu_{c_i}\) is the centroid of cluster \(c_i\). The algorithm iteratively refines cluster centroids until convergence, ensuring high intra-cluster similarity and low inter-cluster similarity.
2.2 Scenario Construction
We categorize EV charging scenarios based on daily charging patterns and urban functional zones. Using charging data from 22,488 EV chargers in Shijiazhuang, we analyze charging records across three time intervals:
- Nighttime (22:00–06:00)
- Noontime (11:00–15:00)
- Other periods (06:00–11:00 and 15:00–22:00)
By applying K-means with the elbow method to determine the optimal cluster number (\(K=4\)), we define four scenarios:
- Low-frequency usage: Chargers with sparse charging activity in all intervals, typically in remote areas or private installations.
- Workplace scenario: Higher charging activity during noontime, aligning with office hours.
- Residential scenario: Peak charging at nighttime, reflecting home-based charging habits.
- High-traffic scenario: Uniformly high charging activity across all intervals, located in commercial districts or transportation hubs.
Table 1 summarizes the key characteristics of each scenario.
Table 1. Charging Scenarios Identified by K-means Clustering
| Scenario | Primary Time Interval | Charging Behavior Pattern | Typical Location |
|---|---|---|---|
| Low-frequency | All intervals (low) | Sparse, irregular charging | Rural areas, private homes |
| Workplace | Noontime (high) | Daytime charging during work hours | Office complexes |
| Residential | Nighttime (high) | Evening and early morning charging | Residential neighborhoods |
| High-traffic | All intervals (high) | Continuous, high-demand charging | Commercial centers, hubs |
3. TransLSTM Model for Charging Load Forecasting
3.1 Model Architecture
The TransLSTM model combines the strengths of Transformer and LSTM. The encoder uses self-attention to capture relationships between multi-dimensional features (e.g., historical load, weather data), while the decoder employs LSTM to model temporal dependencies.
3.1.1 Encoder with Self-Attention
The encoder processes a sequence of input features \(X = [x_1, x_2, \dots, x_T]\) augmented with positional encoding P to retain temporal information:
\(X’ = X + P\)
Query (Q), key (K), and value (V) matrices are generated via linear projections:
\(Q = W_q X’, \quad K = W_k X’, \quad V = W_v X’\)
The scaled dot-product attention mechanism computes attention scores and outputs:
\(\text{Attention}(Q, K, V) = \text{softmax}\left( \frac{QK^T}{\sqrt{d_k}} \right) V\)
Multi-head attention combines multiple attention heads to capture diverse feature interactions. Residual connections and layer normalization ensure training stability:
\(A’ = \text{LayerNorm}(X’ + \text{MultiHead}(Q, K, V))\)
A feed-forward network further processes the output:
\(f = \text{ReLU}(W_1 A’ + b_1) W_2 + b_2\)
The final encoder output \(h_{\text{Encoder}}\) is:
\(h_{\text{Encoder}} = \text{LayerNorm}(A’ + f)\)
3.1.2 Decoder with LSTM
The decoder integrates LSTM to model sequential dependencies. At each time step t, the encoder output \(h_{\text{Encoder}}\) and previous LSTM hidden state \(h_{t-1}\) are concatenated and projected to form a aggregated state \(h’_{t-1}\):
\(h’_{t-1} = W \cdot [h_{\text{Encoder}}, h_{t-1}] + b\)
This state is fed into the LSTM cell, which updates its hidden state \(h_t\) and cell state \(C_t\) using forget, input, and output gates:
\(\begin{align*} f_t &= \sigma(W_f \cdot [h’_{t-1}, x_t] + b_f) \\ i_t &= \sigma(W_i \cdot [h’_{t-1}, x_t] + b_i) \\ \tilde{C}_t &= \tanh(W_C \cdot [h’_{t-1}, x_t] + b_C) \\ C_t &= f_t \cdot C_{t-1} + i_t \cdot \tilde{C}_t \\ o_t &= \sigma(W_o \cdot [h’_{t-1}, x_t] + b_o) \\ h_t &= o_t \cdot \tanh(C_t) \end{align*}\)
The final prediction \(O_t\) is generated via a linear layer:
\(O_t = \text{Linear}(h_t)\)
3.2 Model Training
The model is trained using the Adam optimizer with a learning rate of 0.001 and a batch size of 32. We optimize for mean squared error (MSE) as the loss function:
\(\text{MSE} = \frac{1}{n} \sum_{t=1}^{n} (A_t – F_t)^2\)
where \(A_t\) is the actual load and \(F_t\) is the forecasted load.
4. Experimental Setup and Results
4.1 Dataset
We use real-world EV charging data from Shijiazhuang (January 1 to July 12, 2023), including:
- Charging load: 15-minute interval data from 22,488 chargers.
- Weather data: Temperature, humidity, wind speed, wind direction, and precipitation.
The dataset is split into training (80%) and testing (20%) sets.
4.2 Feature Selection
Pearson and Spearman correlation analyses are performed to identify significant features. Table 2 shows that humidity, wind speed, and wind direction are strongly correlated with charging load, while temperature and precipitation have weak correlations. Thus, we include load, humidity, wind speed, and wind direction as input features.
Table 2. Correlation Analysis Results
| Feature | Pearson Correlation | Spearman Correlation |
|---|---|---|
| Temperature | -0.0413 | -0.0285 |
| Humidity | 0.2693 | 0.2574 |
| Wind Speed | -0.2549 | -0.2576 |
| Wind Direction | 0.2382 | 0.2397 |
| Precipitation | 0.0560 | 0.0111 |
4.3 Model Comparison
We compare the following models:
- Transformer: Pure Transformer model.
- LSTM: Pure LSTM model.
- TransLSTM: Transformer encoder + LSTM decoder.
- Scenario-LSTM: LSTM with scenario-based clustering.
- Scenario-TransLSTM: TransLSTM with scenario-based clustering.
4.4 Evaluation Metrics
Four metrics are used to assess performance:
- Mean Squared Error (MSE)
- Mean Absolute Error (MAE)
- Mean Absolute Percentage Error (MAPE)
- Coefficient of Determination (R²)
Their formulas are:
\(\begin{align*} \text{MAE} &= \frac{1}{n} \sum_{t=1}^{n} |A_t – F_t| \\ \text{MAPE} &= \frac{1}{n} \sum_{t=1}^{n} \left| \frac{A_t – F_t}{A_t} \right| \times 100\% \\ R^2 &= 1 – \frac{\sum_{t=1}^{n} (A_t – F_t)^2}{\sum_{t=1}^{n} (A_t – \bar{A})^2} \end{align*}\)
4.5 Results
Table 3. Prediction Performance for 15-Minute Forecasting
| Model | MSE (kW²) | MAE (kW) | MAPE (%) | R² |
|---|---|---|---|---|
| Transformer | 0.00107 | 0.0198 | 8.98 | 0.941 |
| LSTM | 0.000691 | 0.0179 | 8.34 | 0.958 |
| TransLSTM | 0.000570 | 0.0151 | 7.48 | 0.972 |
| Scenario-LSTM | 0.000563 | 0.0155 | 6.12 | 0.989 |
| Scenario-TransLSTM | 0.000526 | 0.0137 | 6.36 | 0.992 |
Table 4. Prediction Performance for 1-Hour Forecasting
| Model | MSE (kW²) | MAE (kW) | MAPE (%) | R² |
|---|---|---|---|---|
| Transformer | 0.00211 | 0.0469 | 15.2 | 0.836 |
| LSTM | 0.00172 | 0.0388 | 14.6 | 0.897 |
| TransLSTM | 0.00129 | 0.0320 | 12.5 | 0.908 |
| Scenario-LSTM | 0.00108 | 0.0289 | 11.3 | 0.931 |
| Scenario-TransLSTM | 0.000904 | 0.0172 | 8.34 | 0.955 |
Table 5. Prediction Performance for 4-Hour Forecasting
| Model | MSE (kW²) | MAE (kW) | MAPE (%) | R² |
|---|---|---|---|---|
| Transformer | 0.0136 | 0.1127 | 17.21 | 0.614 |
| LSTM | 0.0115 | 0.0991 | 15.97 | 0.679 |
| TransLSTM | 0.00944 | 0.0914 | 15.44 | 0.701 |
| Scenario-LSTM | 0.00873 | 0.0860 | 14.23 | 0.733 |
| Scenario-TransLSTM | 0.00670 | 0.0753 | 13.91 | 0.752 |
5. Discussion
5.1 Model Performance
The Scenario-TransLSTM model outperforms all other models across all time scales. For 1-hour forecasting, it achieves a 38.8% reduction in MSE compared to Transformer and a 25% reduction compared to LSTM. This demonstrates the effectiveness of combining scenario-based clustering with the TransLSTM architecture.
5.2 Impact of Scenario-based Analysis
Clustering significantly improves prediction accuracy. Scenario-LSTM and Scenario-TransLSTM models consistently outperform their non-scenario counterparts. For example, in 15-minute forecasting, Scenario-TransLSTM reduces MSE by 7.7% compared to TransLSTM, highlighting the value of tailoring models to specific charging behaviors.
5.3 Feature Contribution
Including weather features (humidity, wind speed, direction) enhances accuracy. Multi-feature input reduces MSE by 52.17% in Scenario-TransLSTM compared to single-feature (load only) input, confirming the importance of multi-dimensional data in EV load forecasting.
6. Conclusion
This study presents a robust framework for ultra-short-term forecasting of electric vehicle charging loads. By integrating K-means clustering for scenario analysis and an improved TransLSTM model, we effectively capture both spatial-temporal charging patterns and multi-dimensional feature interactions. Experimental results on real-world data validate the superiority of the proposed Scenario-TransLSTM model, which achieves higher prediction accuracy than traditional LSTM and Transformer models across various time scales.
Future research directions include extending the framework to larger datasets, incorporating real-time traffic data, and exploring advanced deep learning architectures for enhanced scalability and generalization.