AI & Machine Learning Model Accuracy Converter
True Negatives: ${trueNegatives.toFixed(0)}
False Negatives: ${falseNegatives.toFixed(0)}
Accuracy: ${(accuracy * 100).toFixed(2)}%
Precision: ${(precision * 100).toFixed(2)}%
Recall: ${(recall * 100).toFixed(2)}%
F1 Score: ${(f1Score * 100).toFixed(2)}%
`; resultSection.innerHTML = resultText; resultSection.style.display = 'block'; pdfButton.disabled = false; }; const downloadPDF = () => { if (!currentResults.modelType || !resultSection.innerText) { errorMessage.textContent = 'No results available to download.'; errorMessage.style.display = 'block'; return; } try { const { jsPDF } = window.jspdf; if (!jsPDF) { console.error('jsPDF is not loaded.'); errorMessage.textContent = 'PDF generation failed. Please try again.'; errorMessage.style.display = 'block'; return; } const doc = new jsPDF(); doc.setFont('helvetica', 'bold'); doc.setFontSize(16); doc.text('AI & Machine Learning Model Accuracy Converter', 20, 20); doc.setLineWidth(0.5); doc.line(20, 25, 190, 25); doc.setFont('helvetica', 'normal'); doc.setFontSize(12); const modelTypeDisplay = currentResults.modelType.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); doc.text(`Model Type: ${modelTypeDisplay}`, 20, 40); doc.text(`True Positives: ${currentResults.truePositives.toFixed(0)}`, 20, 50); doc.text(`False Positives: ${currentResults.falsePositives.toFixed(0)}`, 20, 60); doc.text(`True Negatives: ${currentResults.trueNegatives.toFixed(0)}`, 20, 70); doc.text(`False Negatives: ${currentResults.falseNegatives.toFixed(0)}`, 20, 80); doc.text(`Accuracy: ${(currentResults.accuracy * 100).toFixed(2)}%`, 20, 90); doc.text(`Precision: ${(currentResults.precision * 100).toFixed(2)}%`, 20, 100); doc.text(`Recall: ${(currentResults.recall * 100).toFixed(2)}%`, 20, 110); doc.text(`F1 Score: ${(currentResults.f1Score * 100).toFixed(2)}%`, 20, 120); doc.setDrawColor(200); doc.rect(15, 35, 180, 90); doc.save('model_accuracy.pdf'); } catch (error) { console.error('PDF generation error:', error); errorMessage.textContent = 'Failed to generate PDF. Please try again.'; errorMessage.style.display = 'block'; } }; const resetForm = () => { converterForm.reset(); resultSection.innerHTML = ''; resultSection.style.display = 'none'; errorMessage.style.display = 'none'; pdfButton.disabled = true; currentResults = { truePositives: 0, falsePositives: 0, trueNegatives: 0, falseNegatives: 0, modelType: '', accuracy: 0, precision: 0, recall: 0, f1Score: 0 }; truePositivesInput.focus(); }; convertButton.addEventListener('click', calculateAccuracyMetrics); resetButton.addEventListener('click', resetForm); pdfButton.addEventListener('click', downloadPDF); converterForm.addEventListener('submit', (e) => { e.preventDefault(); calculateAccuracyMetrics(); }); }); })();