# Research on Optimized Energy Scheduling of Rural Microgrid
## 4 Short-Term Rural Electricity Load Forecast
### Identify Sample Data and Build the Predictive Model  
By analyzing the factors affecting the growth of crops and household consumption, the sample data of rural area electricity load prediction is preliminarily determined. It is worth noting that the sample data used to predict agricultural load are different from the sample data used to predict residential load, and their prediction is carried out separately. More specific data samples are shown in Tables 1 and 2.  
Then the prediction model is established, which is divided into three steps: sample data preprocessing, training model and load prediction, as shown below.  
Step 1: Data preprocessing. First, the sample data in Tables 1 and 2 is subjected to outlier detection, abnormal elimination and mean interpolation. Then, the Pearson correlation coefficient of the multi-dimensional vector is used as the correlation index to analyze the correlation of the sample data. The calculated correlation thermodynamic diagram is shown in Figures 4 and 5. According to the figures, the correlation of the preliminarily selected sample data is high, so that they can all be used for prediction. Finally, the selected sample data is divided into the training set, verification set and test set by cross-validation.  
Step 2: Training model. The pre-processed data is input into the XGBoost predictive model. The XGBoost model uses the greedy algorithm to calculate the parameter allocation of the decision tree layer by layer, thereby minimizing the objective function. Then, we use the verification set to judge whether the model is excellent. If it does not meet the criteria, continue to optimize the parameters until the best results are achieved and the final prediction model will be saved.  
Step 3: Load prediction. According to the error indexes between the predicted value and the actual value: Root Mean Square Error (_RMSE_) and Mean Absolute Percentage Error (_MAPE_), the optimal model is selected as the load prediction model to obtain the optimal load prediction results.  
\begin{table}
\begin{tabular}{c c c} \hline \hline  & **Parm** & **Meaning** \\ \hline \multirow{6}{*}{Input} & f0 & Day of the week \\  & f1 & Holidays or working days \\  & f2 & Season \\  & f3 & Data (year/month/day) \\  & f4 & Weather \\  & f5 & Temperature \\  & f6 & Resident population \\  & f7 & Type of career (farmer/non-farmer) \\  & f8 & Demographic age \\  & f9 & Residential area \\ \hline Output & Y1 & Predicted residential load \\ \hline \hline \end{tabular}
\end{table}
Table 1: Sample data of residential load forecasting.  
\begin{table}
\begin{tabular}{c c c} \hline \hline  & **Parm** & **Meaning** \\ \hline \multirow{6}{*}{Input} & f1 & Temperature \\  & f2 & Sunlight intensity \\  & f3 & Weather \\  & f4 & Growth stage of crop \\  & f5 & Crop type \\  & f6 & CO\({}_{2}\) concentration in greenhouse \\  & f7 & Air humidity in greenhouse \\  & f8 & Soil moisture in greenhouse \\ \hline Output & Y1 & Predicted greenhouse load \\ \hline \hline \end{tabular}
\end{table}
Table 2: Sample data of agricultural load forecasting.  
\[RMSE\ =\sqrt{\frac{1}{n}\sum_{i\ =\ 1}^{n}\left(y_{i}-\hat{y}_{i}\right)^{2}}, \tag{15}\]  
\[MAPE\ =\frac{1}{n}\sum_{i\ =\ 1}^{n}\left|\frac{y_{i}-\hat{y}_{i}}{y_{i}} \right|\times 100\%, \tag{16}\]  
where, \(n\) is the number of predicted values. The smaller the values of \(RMSE\) and \(MAPE\), the closer the predicted value (\(\hat{y}_{i}\)) is to the true value (\(y_{i}\)), and the better the prediction model works.