# The Integration of Internet of Things and Machine Learning for Energy Prediction of Wind Turbines
## 3 ML for Wind Energy Prediction
### Machine Learning and Wind Energy Forecast
#### 3.2.2 Random Forest Regression  
[PERSON] (2008) and [PERSON] (2010) proposed the Random Forest Regression (RFR) algorithm in 2001 as an ML method for both regression and classification tasks. Categorical regression tree (CART) techniques can be classified into two categories depending on the nature of the output variables: regression decision trees and categorical decision trees. It is a flexible ML technique employed for prediction of numerical values. In order to  
Figure 17: (**a**) Actual vs. predicted values, (**b**) residual vs. predicted values. reduce overfitting and improve accuracy, it uses the predictions of many decision trees [37]. Python's machine-learning modules facilitate the efficient optimization and implementation of this method. Random forest regression involves adjustable parameters, similar to other ML techniques. Some of the factors that influence a regression tree include the minimum number of observations at each terminal node, the fraction of data to sample in each regression tree, the number of trees, and the number of predictor variables randomly picked at each node [38]. Cross-validation is employed to optimize these independent parameters. It is often recommended to set the number of decision trees to a high value in order to achieve a steady minimum for the prediction error, rather than making adjustments. The equation for the generalization error and margin function in random forest is given as follows:  
\[PE^{*}=P_{X,Y}(mg(X,Y)<0) \tag{10}\]  
where  
\[mg(X,Y)=av_{k}I(h_{k}(X)=Y)-\underset{j\
eq Y}{max}_{k}I(h_{k}(X)=j) \tag{11}\]  
The equation's relevant term, \(av_{k}\), specifies the weighting of each tree's vote to determine the final classification or regression output. Let \(X\) and \(Y\) represent random vectors. The margin function, \(mg\), determines the average votes for the correct output compared to other outputs. The function \(I(. )\) is an indicator function, and \(h_{\kappa}\) represents the classifiers. In Random Forest regression, RandomizedSearchCV is employed to optimize the model's hyperparameters by exploring a spectrum of potential parameter values [39]. The get_param_grid method produces a dictionary of hyperparameters and their associated values for tuning in the Random Forest model. Each key in the dictionary signifies a hyperparameter (n_estimators: the number of trees in the forest, max_depth: the maximum depth of every tree in the forest, min_samples_split: the minimum number of samples required to split an internal node, min_samples_leaf: the minimum number of samples required to be at a leaf node) and the corresponding list comprises various values that RandomizedSearchCV will investigate. The implementation of the RFR technique, along with cross-validation results, yielded the aforementioned metrics [40]:  
* R\({}^{2}\) (0.76087): An R\({}^{2}\) of 0.76087 signifies that the model accounts for approximately 76.09% of the variance in the target variable, which is commendable. The model effectively catches most patterns within the data. * Adjusted R\({}^{2}\) (0.76060): Adjusted R\({}^{2}\) is closely aligned with the R\({}^{2}\), indicating that the model is appropriately fitted without superfluous complexity. * MSE (0.01976): The MSE is notably low, signifying that the model's prediction errors are minimal. * RMSE (0.14057): An RMSE of 0.14057 implies that, on average, the model's predictions diverge from the actual values by approximately 0.14 units, reflecting commendable performance, particularly relative to the data's scale. * MAE (0.10439): An MAE of 0.10439 indicates that, on average, the model's predictions deviate by around 0.10 units. Given that MAE exhibits less sensitivity to outliers compared to MSE, it indicates that the model is continuously producing relatively minor mistakes. Mean Cross-Validation Results: Better knowledge of how the model spans several subsets of the data comes from cross-valuation results.