## 6 DNN Modeling, Training, and Testing  
At this point, the input data or features and the output data or labels are ready to form training examples. The next step is for the DNN model to be created. The training examples will first be randomly shuffled, then divided into two sets, a training set and a test set, usually in a ratio of around 70/30 or so, respectively. The training set will be used by the DNN to learn, while the test set will not be seen until the learning is completed. The training data makes up 75% of the total 17,520 training examples of  
* 104 inputs, from which i. 41 Loads-active power, ii. 41 Loads-reactive power, iii. 9 PVs-active power, iv. 9 PVs-reactive power, v. 4 EV charging station active powers (2 ports for each charging station),
* 86 outputs, a neuron for each of the following transformer taps: i. 45 neurons: 5 taps \(\times\) 9 E-OLTCs, ii. 20 neurons: 5 taps \(\times\) 4 LVRs, iii. 21 neurons: 21 taps \(\times\) 1 Primary SS. Each of the output neurons will assume values between zero and one. That value represents the probability of that certain tap of that certain transformer to be the correct one. \begin{table}
\begin{tabular}{l c c c c c} \hline \hline  & **60\% \(P_{n}\)** & **80\% \(P_{n}\)** & **100\% \(P_{n}\)** & **120\% \(P_{n}\)** & **140\% \(P_{n}\)** \\ \hline V \(>\) 1.05 p.u & 0 & 0 & 265 & 894 & 1643 \\ \hline V \(>\) 1.10 p.u & 0 & 0 & 0 & 1 & 80 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Over-voltage violations in one year as a function of penetration level of PVs. Figure 13: Number of over-voltages as a function of penetration level of PVs. As for the machine-learning algorithm, a significant amount of time was taken trying out different learning rates, batch sizes, number of epochs, number of neurons in the hidden layer, activation functions, and various optimization algorithms and architectures. This specific algorithm was chosen while keeping in mind that the voltage in busbars in reality can vary around 10% without breaching any limits, which means that the immediate transformer's tap position can assume more than one correct position. That automatically leads us to a multi-output output layer and a non-exclusive algorithm with an adequate loss function which allows for multiple neurons to show a high probability simultaneously. Considering all that, the following settings were chosen:  
* The DNN is'multi-output'. * The algorithm is 'non-exclusive'. * Classification should be binary, using the 'Sigmoid activation function' in the output layer. * The loss function is 'Binary Cross-entropy'. * In the input layer, there are 104 neurons. * There are two hidden layers: the first, with 96 neurons, and the second, with 90 neurons. * The number of neurons in the output layer will be 5-Ndevices (E-OLTC, LVRs, and PSS). So, 86 neurons in total. The DNN has basic architecture as shown in Figure 14.  
Speaking at a high level, the DNN has the following flow process:  
1. The input (feature) and output (label) data are imported. 2. The dataset is shuffled randomly and split into a training set and a test set. 3. The data is scaled. 4. The DNN is built by choosing the number of neurons in layers, the activation functions, the optimizer, etc. 5. The DNN is trained. 6. The DNN is tested. 7. The DNN predictions are exported. When the DNN has learned well enough, the test set will be fed to it. This way, the DNN will have to predict the outputs for inputs it has never seen before. The loss function that measures the numerical performance of the DNN in this model is Binary Cross-entropy. It is a logarithmic function, expressed as follows:  
\[CE=-t_{1}\text{log}\left(f(s_{1})\right)-(1-t_{1})\text{log}(1-f(s_{1}))\]  
Figure 14: Scheme of the DNN architecture. where \(f(s_{1})=\frac{1}{1+e^{s_{1}}}\). This loss function is represented in Figure 15. It can be seen from this logarithmic graph that DNN is learning fast, as it sees a significant decrease after only around 15 epochs.