background image

49 

 

π‘π‘Ÿπ‘’π‘π‘–π‘ π‘–π‘œπ‘› =

π‘‘π‘Ÿπ‘’π‘’ π‘π‘œπ‘ π‘–𝑑𝑖𝑣𝑒

π‘‘π‘Ÿπ‘’π‘’ π‘π‘œπ‘ π‘–𝑑𝑖𝑣𝑒 + π‘“π‘Žπ‘™π‘ π‘’ π‘π‘œπ‘ π‘–𝑑𝑖𝑣𝑒

 

Equation 7: precision equation 

Recall (

Equation 8

) is the ability of the model to find all the positive values in the dataset for this 

instance: 

π‘Ÿπ‘’π‘π‘Žπ‘™π‘™ =

π‘‘π‘Ÿπ‘’π‘’ π‘π‘œπ‘ π‘–𝑑𝑖𝑣𝑒

π‘‘π‘Ÿπ‘’π‘’ π‘π‘œπ‘ π‘–𝑑𝑖𝑣𝑒 + π‘“π‘Žπ‘™π‘ π‘’ π‘›π‘’π‘”π‘Žπ‘‘𝑖𝑣𝑒

 

Equation 8: recall equation 

F1-score (

Equation 9

) is the harmonic mean of precision and recall, and is a measure of the 

model’s accuracy, for the classification of each instance: 

𝐹

1

=

2

π‘π‘Ÿπ‘’π‘π‘–π‘ π‘–π‘œπ‘›

βˆ’1

+ π‘Ÿπ‘’π‘π‘Žπ‘™π‘™

βˆ’1

=

π‘π‘Ÿπ‘’π‘π‘–π‘ π‘–π‘œπ‘› βˆ™ π‘Ÿπ‘’π‘π‘Žπ‘™π‘™

π‘π‘Ÿπ‘’π‘π‘–π‘ π‘–π‘œπ‘› + π‘Ÿπ‘’π‘π‘Žπ‘™π‘™

=

𝑇𝑃

𝑇𝑃 +

1
2

(𝐹𝑃 + πΉπ‘)

 

Equation 9: F1-score - harmonic mean equation 

Lastly, Support is simply the times that each specific class is encountered in the dataset, the 
instances of each label. It is from those instances that the precision and recall are calculated 
for each label of the dataset, in a binary way (one-against-all). 

The average values of the report below the label-by-label metrics lead the results from binary 
to multiclass classification [34]. Most importantly, accuracy (

Equation 11

,

Equation 11

) measures 

the overall ability of the model to classify correctly over all of the values. If π‘¦

𝑖

Μ‚ is the predicted 

value of sample π‘– and π‘¦

𝑖

 is the real value, then accuracy is defined as: 

π‘Žπ‘π‘π‘’π‘Ÿπ‘Žπ‘π‘¦(𝑦, π‘¦Μ‚) =

1

𝑛

π‘ π‘Žπ‘šπ‘π‘™π‘’π‘ 

βˆ‘

1(𝑦

𝑖

Μ‚ = π‘¦

𝑖

)

𝑛

π‘ π‘Žπ‘šπ‘π‘™π‘’π‘ 

βˆ’1

𝑖=0

 

Equation 10: accuracy equation 

Or more intuitively: 

π‘Žπ‘π‘π‘’π‘Ÿπ‘Žπ‘π‘¦ =

𝑇𝑃 + π‘‡π‘

𝑇𝑃 + π‘‡π‘ + πΉπ‘ƒ + πΉπ‘

=

π‘π‘œπ‘Ÿπ‘Ÿπ‘’π‘π‘‘ π‘π‘™π‘Žπ‘ π‘ π‘–π‘“π‘–π‘π‘Žπ‘‘π‘–π‘œπ‘›π‘ 

π‘Žπ‘™π‘™ π‘π‘™π‘Žπ‘ π‘ π‘–π‘“π‘–π‘π‘Žπ‘‘π‘–π‘œπ‘›π‘ 

 

Equation 11: intuitive accuracy equation 

Macro average is simply the mean of all the above binary metrics, for precision, recall and f-1 
score respectively, taking all classes as of equal importance, which is often untrue, especially 
in unbalanced datasets such as NSL-KDD; weighted average is the mean value of the binary 
metrics, with each class’s score weighted by its presence in the dataset (the support value). 
The weighted average is much closer to the accuracy score, as we can see in the classification