The proper explanation for the general formula of the DU?
My answer is based on V. Pellegrin, J. Chem. Educ. 1983, 60 (8), 626 which might be inaccessible for you by a pay wall.

Starting with Eulers characteristic for planar graphs wich states that adding the faces and vertices of a planar graph and substracting all the edges must be 1 $$F+V-E=1$$ which can be rewritten as $$F=1+E-V$$
Now in more chemical words we can redefine this by saying that edges are bonds and vertices are atoms and the $F$ will be our $DU$ from now on. If we know the structural formula we could stop now, count all atoms and bonds and calculate what we want to know. Those are two examples from the paper:



But what if all we have is a sum formula from let's say mass spectrometry?

Then we have to calculate how many bonds this molecule will have based on the knowledge of how many atoms the molecule contains and how many valence electrons each atom has.

Each molecule consists of $$N=\sum_i n_i$$ atoms of element $i$ whereby $n_i$ denotes the amount of each element. Each atom has to be assumed in it's lowest valency state and has $v_i$ valence electrons which would make in total $$\sum_{i=1}^N n_i~v_i$$ valence electrons. As every single bond contains two electrons, the amount of all possible bonds is half the amount of all valence electrons, namely $$\sum_{i=1}^N \frac{n_i~v_i}{2}$$

Let's try it with the mass formula $\ce{C9H7NO}$:


The molecule consists of $N=18$ atoms.
The atoms are grouped in $4$ groups containing the elements $i=\{C,H,N,O\}$
Each element is contained $n=\{9,7,1,1\}$ times.
The lowest valency of each contained atom is $v=\{4,1,3,2\}$
The sum of all valence electrons is $\sum_{i=1}^N n_i v_i=9\cdot4+7\cdot1+1\cdot3+1\cdot2=48$
The sum of all possible bonds is $\sum_{i=1}^N \frac{n_i~v_i}{2}=48/2=24$


Now let's insert those numbers into the equation $$DU=1+E-V=1+24-18=7$$ Because I knew the moleule that I have chosen we can compare


and see that the calculation was correct ($5$ for the double bonds + $2$ for the ring closures).

As it was correct, we can combine it and derive your equation.
$$\begin{align}
F=&amp;~1+E-V\\
DU=&amp;~1+\text{number of bonds}-\text{number of atoms}\\
DU=&amp;~1+\sum_{i=1}^N \frac{n_i~v_i}{2}-\sum_{i=1}^N n_i\\
DU=&amp;~1+\sum_{i=1}^N \left(\frac{n_i~v_i}{2}-n_i\right)\\
DU=&amp;~1+\frac{1}{2}\sum_{i=1}^N (n_i~v_i-2~n_i)\\
DU=&amp;~1+\frac{1}{2}\sum_{i=1}^N n_i~(v_i-2)\\
\end{align}$$