Spaces:
Running
Running
File size: 9,879 Bytes
4f5578c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Convergence Plot - Model Fitting</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 20px;
padding: 30px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
font-size: 2em;
}
.controls {
display: flex;
justify-content: center;
gap: 15px;
margin-bottom: 30px;
flex-wrap: wrap;
}
button {
padding: 12px 30px;
font-size: 16px;
border: none;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
.btn-underfit {
background: #3498db;
color: white;
}
.btn-bestfit {
background: #2ecc71;
color: white;
}
.btn-overfit {
background: #e74c3c;
color: white;
}
.chart-container {
position: relative;
height: 400px;
margin-bottom: 30px;
}
.info-box {
background: #f8f9fa;
border-left: 5px solid #667eea;
padding: 20px;
border-radius: 8px;
margin-top: 20px;
}
.info-box h3 {
color: #667eea;
margin-bottom: 10px;
}
.info-box p {
color: #555;
line-height: 1.6;
margin-bottom: 10px;
}
.legend {
display: flex;
justify-content: center;
gap: 30px;
margin-top: 20px;
flex-wrap: wrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.legend-color {
width: 30px;
height: 4px;
border-radius: 2px;
}
.train { background: #3498db; }
.val { background: #e74c3c; }
</style>
</head>
<body>
<div class="container">
<h1>📊 Model Convergence Playground</h1>
<div class="controls">
<button class="btn-underfit" onclick="showUnderfitting()">Underfitting</button>
<button class="btn-bestfit" onclick="showBestFit()">Best Fit</button>
<button class="btn-overfit" onclick="showOverfitting()">Overfitting</button>
</div>
<div class="chart-container">
<canvas id="convergenceChart"></canvas>
</div>
<div class="legend">
<div class="legend-item">
<div class="legend-color train"></div>
<span>Training Loss</span>
</div>
<div class="legend-item">
<div class="legend-color val"></div>
<span>Validation Loss</span>
</div>
</div>
<div class="info-box" id="infoBox">
<h3>Select a scenario to begin</h3>
<p>Click one of the buttons above to see how different model fitting scenarios affect convergence.</p>
</div>
</div>
<script>
let chart;
const ctx = document.getElementById('convergenceChart').getContext('2d');
const scenarios = {
underfit: {
title: '🔵 Underfitting (High Bias)',
description: 'The model is too simple to capture the underlying patterns in the data.',
characteristics: [
'• Both training and validation losses remain high',
'• The model has not learned enough from the data',
'• Poor performance on both training and validation sets',
'• Solution: Increase model complexity, add more features, or train longer'
],
trainLoss: [0.8, 0.72, 0.68, 0.65, 0.63, 0.62, 0.61, 0.605, 0.602, 0.60],
valLoss: [0.82, 0.75, 0.70, 0.68, 0.66, 0.65, 0.64, 0.635, 0.632, 0.63]
},
bestfit: {
title: '🟢 Best Fit (Good Generalization)',
description: 'The model has learned the underlying patterns without memorizing noise.',
characteristics: [
'• Both losses decrease together and converge to low values',
'• Small gap between training and validation loss',
'• Model generalizes well to unseen data',
'• This is the ideal scenario for deployment'
],
trainLoss: [0.9, 0.65, 0.45, 0.32, 0.23, 0.17, 0.13, 0.10, 0.08, 0.07],
valLoss: [0.92, 0.68, 0.48, 0.35, 0.26, 0.20, 0.16, 0.13, 0.11, 0.10]
},
overfit: {
title: '🔴 Overfitting (High Variance)',
description: 'The model has memorized the training data including its noise and outliers.',
characteristics: [
'• Training loss continues to decrease',
'• Validation loss starts increasing after initial decrease',
'• Large gap between training and validation performance',
'• Solution: Add regularization, use dropout, get more data, or early stopping'
],
trainLoss: [0.9, 0.6, 0.4, 0.25, 0.15, 0.08, 0.04, 0.02, 0.01, 0.005],
valLoss: [0.92, 0.65, 0.45, 0.35, 0.32, 0.35, 0.42, 0.50, 0.58, 0.65]
}
};
function createChart(trainData, valData) {
if (chart) {
chart.destroy();
}
const epochs = Array.from({length: trainData.length}, (_, i) => i + 1);
chart = new Chart(ctx, {
type: 'line',
data: {
labels: epochs,
datasets: [{
label: 'Training Loss',
data: trainData,
borderColor: '#3498db',
backgroundColor: 'rgba(52, 152, 219, 0.1)',
borderWidth: 3,
tension: 0.4,
pointRadius: 5,
pointHoverRadius: 7
}, {
label: 'Validation Loss',
data: valData,
borderColor: '#e74c3c',
backgroundColor: 'rgba(231, 76, 60, 0.1)',
borderWidth: 3,
tension: 0.4,
pointRadius: 5,
pointHoverRadius: 7
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
},
tooltip: {
mode: 'index',
intersect: false
}
},
scales: {
x: {
title: {
display: true,
text: 'Epoch',
font: { size: 14, weight: 'bold' }
},
grid: { color: '#e0e0e0' }
},
y: {
title: {
display: true,
text: 'Loss',
font: { size: 14, weight: 'bold' }
},
beginAtZero: true,
grid: { color: '#e0e0e0' }
}
}
}
});
}
function updateInfo(scenario) {
const info = scenarios[scenario];
const infoBox = document.getElementById('infoBox');
infoBox.innerHTML = `
<h3>${info.title}</h3>
<p><strong>${info.description}</strong></p>
<p><strong>Characteristics:</strong></p>
${info.characteristics.map(c => `<p>${c}</p>`).join('')}
`;
}
function showUnderfitting() {
createChart(scenarios.underfit.trainLoss, scenarios.underfit.valLoss);
updateInfo('underfit');
}
function showBestFit() {
createChart(scenarios.bestfit.trainLoss, scenarios.bestfit.valLoss);
updateInfo('bestfit');
}
function showOverfitting() {
createChart(scenarios.overfit.trainLoss, scenarios.overfit.valLoss);
updateInfo('overfit');
}
// Initialize with best fit
showBestFit();
</script>
</body>
</html> |