/**
* Interaktiver Konfusionsmatrix- & ML-Kennzahlen-Rechner für FIDP
* IHK ZPA Nord-West AP2
*/
(function() {
function renderConfusionMatrix(containerId) {
const container = document.getElementById(containerId);
if (!container) return;
container.innerHTML = `
📊 Interaktiver Konfusionsmatrix-Rechner (FIDP)
Geben Sie die Werte der 2x2-Konfusionsmatrix ein, um Accuracy, Precision, Recall und F1-Score nach IHK-Formeln live zu berechnen:
Genauigkeit (Accuracy)
-- %
(TP + TN) / Gesamt
Präzision (Precision)
-- %
TP / (TP + FP)
Trefferquote (Recall)
-- %
TP / (TP + FN)
Harmonisches Mittel (F1)
--
2 * (P * R) / (P + R)
`;
function update() {
const tp = parseFloat(document.getElementById('cm_tp').value) || 0;
const fp = parseFloat(document.getElementById('cm_fp').value) || 0;
const fn = parseFloat(document.getElementById('cm_fn').value) || 0;
const tn = parseFloat(document.getElementById('cm_tn').value) || 0;
const total = tp + fp + fn + tn;
if (total === 0) return;
const acc = ((tp + tn) / total) * 100;
const prec = (tp + fp > 0) ? (tp / (tp + fp)) * 100 : 0;
const rec = (tp + fn > 0) ? (tp / (tp + fn)) * 100 : 0;
const p = prec / 100;
const r = rec / 100;
const f1 = (p + r > 0) ? (2 * (p * r) / (p + r)) : 0;
document.getElementById('res_acc').textContent = acc.toFixed(2) + ' %';
document.getElementById('res_prec').textContent = prec.toFixed(2) + ' %';
document.getElementById('res_rec').textContent = rec.toFixed(2) + ' %';
document.getElementById('res_f1').textContent = f1.toFixed(3);
}
['cm_tp', 'cm_fp', 'cm_fn', 'cm_tn'].forEach(id => {
document.getElementById(id).addEventListener('input', update);
});
update();
}
window.renderConfusionMatrix = renderConfusionMatrix;
document.addEventListener('DOMContentLoaded', () => {
if (document.getElementById('confusion-matrix-app')) {
renderConfusionMatrix('confusion-matrix-app');
}
});
})();