# Research on Optimized Energy Scheduling of Rural Microgrid
## 6 Solution Procedure
### Prediction Model Parameter Setting and Prediction Results  
The prediction model is built on the Python 3.7 environment. By collecting information from rural areas to build a database of crop environmental indicators, and the sample data for agricultural load forecasting is selected from [33]. The sample data for residential load forecasting is derived from the University of California Irvine (UCI) dataset [34]. After the sample data is obtained, we build the XGBoost prediction model and set the parameters of the model. The Coefficient of Variance (CV) function in XGBoost model can be used to return the desired number of decision trees after determining the learning rate. Therefore, the parameters of the learning rate and the number of decision trees are first determined, and then the grid search method is used to find the best combination of the tree depth and the minimum leaf node sample weight. Next, adjust the random sampling decision tree scale and regularization parameters. Finally adjust the remaining parameters. The adjustment of parameters requires multiple attempts. By evaluating the size of the indicator and observing the prediction effect, the parameters of XGBoost are finally determined, as shown in Table 3.  
After building the XGBoost prediction model, we use the residential and agricultural sample data to train the model separately. Then, the well-performing models are selected to predict the short-term load of home owners and greenhouses in a rural area of Shanghai, China, respectively. The load prediction result is shown in Figure 8. Among them, Figure 8a is the predicted result of all residential load in a rural microgrid, and it can be found that the predicted values are close to the actual values. There are three reasons why the results of residential load forecasting can be so accurate: first, we treat all home owners as a whole, and then predict its overall load instead of predicting the load of each owner in turn. Compared with the load of a house, the region load fluctuation is more gradual and less affected by subjective factors. Second, rural users' electricity use behavior is relatively simple and their life is more regular than that of urban users. Third, our database is large enough that the time resolution of sample data and predictive model is 1 min. The predicted value is the residential load per minute. Although the predicted value per minute deviates from the actual value, when the data of thirty minutes is added up, the deviation between the predicted value and the actual value of each period will decrease. So, it seems that the predicted values are nearly identical to the actual values when displayed in Figure 8a with a time resolution of 0.5 h. More importantly, the prediction accuracy should be judged based on the value deviation per minute instead of each period. Therefore, we use the data per minute to calculate the values of MAPE and RSME to accurately estimate the prediction accuracy. RMSE and MAPE of residential load are 0.059 and 12.52% respectively. In addition, Figure 8b is the predicted result of all agricultural load in rural microgrid. The growth of greenhouse crops is more controllable and regular than the naturally growing crops, which will make the prediction more accurate. The error indexes of agricultural load are RMSE 0.162 and MAPE 9.84%. It can be seen from Figure 8 that the load of agricultural greenhouses accounts for the majority of the total load. The power consumption of the rural microgrid mainly depends on the agricultural load. Comparing the power consumption of residential load and agricultural load in Figure 8c, it can be found that their peak power appears in different time periods, so they can complement each other in power dispatching.