concept ROC curve in category deep learning

This is an excerpt from Manning's book Deep Learning with JavaScript: Neural networks in TensorFlow.js.
Listing 3.6. Using callback to render ROC curves in the middle of model training
await model.fit(trainData.data, trainData.target, { batchSize, epochs, validationSplit: 0.2, callbacks: { onEpochBegin: async (epoch) => { if ((epoch + 1)% 100 === 0 || epoch === 0 || epoch === 2 || epoch === 4) { #1 const probs = model.predict(testData.data); drawROC(testData.target, probs, epoch); } }, onEpochEnd: async (epoch, logs) => { await ui.updateStatus( `Epoch ${epoch + 1} of ${epochs} completed.`); trainLogs.push(logs); ui.plotLosses(trainLogs); ui.plotAccuracies(trainLogs); } } });
As we have briefly alluded to, an important realization is that the threshold applied on the sigmoid output to pick out positive predictions doesn’t have to be exactly 0.5. In fact, depending on the circumstances, it might be better to set it to a value above 0.5 (but below 1) or to one below 0.5 (but above 0). Lowering the threshold makes the model more liberal in labeling inputs as positive, which leads to higher recall but likely lower precision. On the other hand, raising the threshold causes the model to be more cautious in labeling inputs as positive, which usually leads to higher precision but likely lower recall. So, we can see that there is a trade-off between precision and recall, and this trade-off is hard to quantify with any one of the metrics we’ve talked about so far. Luckily, the rich history of research into binary classification has given us better ways to quantify and visualize this trade-off relation. The ROC curve that we will discuss next is a frequently used tool of this sort.