## 4 The Proposed TransTLA Method
### Transfer Learning Implementation
The domain adaptation loss can be formulated as Equation (19), which accepts feature tensors from the source and target domains, as derived from the attention mechanism layer, as input sample sets. Calculate the Euclidean distance of the difference between the mean vectors of these two sample sets and then compute the square of this difference, guiding the model's domain adaptation. \[\mathcal{L}_{\text{adapt}}=\left\|\mathbb{E}(Y^{\text{source}})-\mathbb{E}(Y^{ \text{target}})\right\|^{2}=\left\|\frac{1}{N_{\text{source}}}\sum_{i=1}^{N_{ \text{source}}}Y_{i}^{\text{source}}-\frac{1}{N_{\text{target}}}\sum_{j=1}^{N _{\text{target}}}Y_{j}^{\text{target}}\right\|^{2} \tag{19}\]  
Combining Equations (16), (17) and (19), the overall loss function can be expressed as  
\[\mathcal{L}=\alpha\cdot\mathcal{L}_{\text{source}}+(1-\alpha)\cdot\mathcal{L}_ {\text{target}}+\beta\cdot\mathcal{L}_{\text{adapt}}, \tag{20}\]  
where \(\alpha\) and \(\beta\) are the balancing weights. By integrating the custom loss function, the model enhances the predictive performance across both source and target domains while facilitating effective knowledge transfer via domain adaptation loss, refining feature representations with each training epoch. Over successive training rounds, the model learns to minimize discrepancies between source and target domain feature tensors, mitigating predictive errors from data distribution inconsistencies. Compared to traditional TL methods, including DAT and MAML, our proposed approach offers several key advantages: (1) Unlike DAT's adversarial training and MAML's meta-learning, our method eliminates complex model transfer and fine-tuning, simplifyingthe training process. (2) By simultaneously optimizing the regression losses and domain adaptation loss for both domains, it simplifies the training process and enables faster learning of common features. (3) This approach mitigates overfitting, especially in data-scarce target domains, enhancing generalization by learning common features across domains. (4) Furthermore, the model progressively adapts to target domain predictive tasks during training, improving the predictive accuracy. It is a continuous adaptation strategy distinct from DAT's adversarial steps or MAML's episodic learning. The training process framework of the home appliance sales forecasting model based on TransTLA is depicted in Figure 6. Initially, source and target domain data are collected and preprocessed. The training data from both domains are then fed into the model network for training. During each training epoch, the model leverages data from both domains to calculate the source domain regression loss, target domain regression loss, and domain adaptation loss. These are weighted and summed to form the overall composite loss function, which is then used for backpropagation to update the model parameters for the next round of training. It is important to note that, despite facing two distinct data domains, we train the same model. The model adjusts its parameters according to the guidance of the composite loss function in each round to achieve TL, thereby improving the performance of home appliance sales forecasting in the target domain. After each epoch, the model's performance is evaluated using the target domain's validation set. If the current model outperforms the previous best model on the validation set, it is updated and saved as the new best model. This process is repeated until a preset number of training epochs is reached. Once training is over, the saved best model is loaded to output and evaluate predictions on the target domain's test set. During the training process, the Adam optimizer is utilized for efficient model parameter tuning, while a dropout strategy is implemented to mitigate overfitting and enhance the model's generalization capability. Furthermore, we employ a dynamic learning rate adjustment method.