Spaces:
Running
Running
Commit ·
05b9f38
1
Parent(s): 0751fec
update files
Browse files- ml_complete-all-topics/app.js +729 -20
- ml_complete-all-topics/index.html +637 -34
- ml_complete-all-topics/style.css +97 -0
ml_complete-all-topics/app.js
CHANGED
|
@@ -65,6 +65,32 @@ let state = {
|
|
| 65 |
}
|
| 66 |
};
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
// Initialize collapsible sections
|
| 69 |
function initSections() {
|
| 70 |
const sections = document.querySelectorAll('.section');
|
|
@@ -110,6 +136,9 @@ function initSections() {
|
|
| 110 |
if (section.id === 'kmeans') initKMeans();
|
| 111 |
if (section.id === 'decision-trees') initDecisionTrees();
|
| 112 |
if (section.id === 'ensemble-methods') initEnsembleMethods();
|
|
|
|
|
|
|
|
|
|
| 113 |
if (section.id === 'algorithm-comparison') initAlgorithmComparison();
|
| 114 |
}
|
| 115 |
});
|
|
@@ -234,7 +263,7 @@ function drawLinearRegression() {
|
|
| 234 |
});
|
| 235 |
mse /= data.linearRegression.length;
|
| 236 |
|
| 237 |
-
lrChart =
|
| 238 |
type: 'scatter',
|
| 239 |
data: {
|
| 240 |
datasets: [
|
|
@@ -284,7 +313,7 @@ function drawLinearRegression() {
|
|
| 284 |
}
|
| 285 |
}
|
| 286 |
}
|
| 287 |
-
});
|
| 288 |
}
|
| 289 |
|
| 290 |
// Gradient Descent Visualization
|
|
@@ -400,7 +429,7 @@ function drawGradientDescent(currentStep = -1) {
|
|
| 400 |
const ctx = canvas.getContext('2d');
|
| 401 |
const lossData = state.gdIterations.map((iter, i) => ({ x: i + 1, y: iter.loss }));
|
| 402 |
|
| 403 |
-
gdChart =
|
| 404 |
type: 'line',
|
| 405 |
data: {
|
| 406 |
datasets: [{
|
|
@@ -445,8 +474,27 @@ function drawGradientDescent(currentStep = -1) {
|
|
| 445 |
});
|
| 446 |
}
|
| 447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
// Initialize everything when DOM is ready
|
| 449 |
function init() {
|
|
|
|
| 450 |
initSections();
|
| 451 |
initTOCLinks();
|
| 452 |
|
|
@@ -512,7 +560,12 @@ function drawSVMBasic() {
|
|
| 512 |
if (!canvas) return;
|
| 513 |
|
| 514 |
const ctx = canvas.getContext('2d');
|
| 515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
const height = canvas.height = 450;
|
| 517 |
|
| 518 |
ctx.clearRect(0, 0, width, height);
|
|
@@ -633,7 +686,12 @@ function drawSVMMargin() {
|
|
| 633 |
if (!canvas) return;
|
| 634 |
|
| 635 |
const ctx = canvas.getContext('2d');
|
| 636 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 637 |
const height = canvas.height = 450;
|
| 638 |
|
| 639 |
ctx.clearRect(0, 0, width, height);
|
|
@@ -754,7 +812,12 @@ function drawSVMCParameter() {
|
|
| 754 |
}
|
| 755 |
|
| 756 |
const ctx = canvas.getContext('2d');
|
| 757 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
const height = canvas.height = 450;
|
| 759 |
|
| 760 |
ctx.clearRect(0, 0, width, height);
|
|
@@ -932,7 +995,12 @@ function drawSVMTraining() {
|
|
| 932 |
if (!canvas) return;
|
| 933 |
|
| 934 |
const ctx = canvas.getContext('2d');
|
| 935 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 936 |
const height = canvas.height = 450;
|
| 937 |
|
| 938 |
ctx.clearRect(0, 0, width, height);
|
|
@@ -2460,7 +2528,7 @@ function drawElbowCurve() {
|
|
| 2460 |
}
|
| 2461 |
}
|
| 2462 |
}
|
| 2463 |
-
});
|
| 2464 |
}
|
| 2465 |
|
| 2466 |
function drawCVKHeatmap() {
|
|
@@ -2855,7 +2923,7 @@ function drawCategoricalNB() {
|
|
| 2855 |
|
| 2856 |
const ctx = canvas.getContext('2d');
|
| 2857 |
|
| 2858 |
-
categoricalNBChart =
|
| 2859 |
type: 'bar',
|
| 2860 |
data: {
|
| 2861 |
labels: ['P(Yes|Rainy,Hot)', 'P(No|Rainy,Hot)'],
|
|
@@ -2907,7 +2975,7 @@ function drawCategoricalNB() {
|
|
| 2907 |
}
|
| 2908 |
}
|
| 2909 |
}
|
| 2910 |
-
});
|
| 2911 |
}
|
| 2912 |
|
| 2913 |
function drawGaussianNB() {
|
|
@@ -3089,7 +3157,7 @@ function drawSpamClassification() {
|
|
| 3089 |
compCanvas.style.marginTop = '20px';
|
| 3090 |
canvas.parentElement.appendChild(compCanvas);
|
| 3091 |
|
| 3092 |
-
bayesComparisonChart =
|
| 3093 |
type: 'bar',
|
| 3094 |
data: {
|
| 3095 |
labels: ['Spam Probability', 'Not-Spam Probability'],
|
|
@@ -3125,8 +3193,8 @@ function drawSpamClassification() {
|
|
| 3125 |
}
|
| 3126 |
}
|
| 3127 |
}
|
| 3128 |
-
});
|
| 3129 |
-
compCanvas.style.height = '150px';
|
| 3130 |
}
|
| 3131 |
}
|
| 3132 |
|
|
@@ -3245,6 +3313,67 @@ function drawDecisionTree() {
|
|
| 3245 |
ctx.fillText('Example: Email with "free" + link → SPAM', 40, height - 20);
|
| 3246 |
}
|
| 3247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3248 |
function drawEntropyViz() {
|
| 3249 |
const canvas = document.getElementById('entropy-viz');
|
| 3250 |
if (!canvas) return;
|
|
@@ -3388,6 +3517,88 @@ function drawSplitComparison() {
|
|
| 3388 |
ctx.fillText('Comparing Split Quality', width / 2, 40);
|
| 3389 |
}
|
| 3390 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3391 |
function drawTreeBoundary() {
|
| 3392 |
const canvas = document.getElementById('tree-boundary');
|
| 3393 |
if (!canvas) return;
|
|
@@ -3587,6 +3798,8 @@ function drawBaggingViz() {
|
|
| 3587 |
ctx.fillText('Bagging: Bootstrap Aggregating', width / 2, 30);
|
| 3588 |
}
|
| 3589 |
|
|
|
|
|
|
|
| 3590 |
function drawBoostingViz() {
|
| 3591 |
const canvas = document.getElementById('boosting-viz');
|
| 3592 |
if (!canvas) return;
|
|
@@ -3962,7 +4175,7 @@ function drawKMeansElbow() {
|
|
| 3962 |
const kValues = [1, 2, 3, 4, 5];
|
| 3963 |
const wcssValues = [50, 18, 10, 8, 7];
|
| 3964 |
|
| 3965 |
-
kmeansElbowChart =
|
| 3966 |
type: 'line',
|
| 3967 |
data: {
|
| 3968 |
labels: kValues,
|
|
@@ -4025,15 +4238,511 @@ function drawKMeansElbow() {
|
|
| 4025 |
}
|
| 4026 |
}
|
| 4027 |
}
|
| 4028 |
-
});
|
| 4029 |
}
|
| 4030 |
|
| 4031 |
-
// Topic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4032 |
function initAlgorithmComparison() {
|
| 4033 |
-
const
|
| 4034 |
-
if (!
|
| 4035 |
-
|
| 4036 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4037 |
}
|
| 4038 |
|
| 4039 |
function drawDecisionFlowchart() {
|
|
|
|
| 65 |
}
|
| 66 |
};
|
| 67 |
|
| 68 |
+
// Initialize category navigation
|
| 69 |
+
function initCategories() {
|
| 70 |
+
const categoryHeaders = document.querySelectorAll('.toc-category-header');
|
| 71 |
+
|
| 72 |
+
categoryHeaders.forEach(header => {
|
| 73 |
+
header.addEventListener('click', () => {
|
| 74 |
+
const category = header.getAttribute('data-category');
|
| 75 |
+
const content = document.getElementById(`${category}-content`);
|
| 76 |
+
const toggle = header.querySelector('.category-toggle');
|
| 77 |
+
|
| 78 |
+
if (content.classList.contains('collapsed')) {
|
| 79 |
+
content.classList.remove('collapsed');
|
| 80 |
+
toggle.classList.remove('collapsed');
|
| 81 |
+
} else {
|
| 82 |
+
content.classList.add('collapsed');
|
| 83 |
+
toggle.classList.add('collapsed');
|
| 84 |
+
}
|
| 85 |
+
});
|
| 86 |
+
});
|
| 87 |
+
|
| 88 |
+
// Start with all categories expanded
|
| 89 |
+
document.querySelectorAll('.toc-category-content').forEach(content => {
|
| 90 |
+
content.classList.remove('collapsed');
|
| 91 |
+
});
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
// Initialize collapsible sections
|
| 95 |
function initSections() {
|
| 96 |
const sections = document.querySelectorAll('.section');
|
|
|
|
| 136 |
if (section.id === 'kmeans') initKMeans();
|
| 137 |
if (section.id === 'decision-trees') initDecisionTrees();
|
| 138 |
if (section.id === 'ensemble-methods') initEnsembleMethods();
|
| 139 |
+
if (section.id === 'rl-intro') { /* No viz for intro */ }
|
| 140 |
+
if (section.id === 'q-learning') { /* Add Q-learning viz if needed */ }
|
| 141 |
+
if (section.id === 'policy-gradient') { /* Add policy gradient viz if needed */ }
|
| 142 |
if (section.id === 'algorithm-comparison') initAlgorithmComparison();
|
| 143 |
}
|
| 144 |
});
|
|
|
|
| 263 |
});
|
| 264 |
mse /= data.linearRegression.length;
|
| 265 |
|
| 266 |
+
lrChart = safeCreateChart(ctx, {
|
| 267 |
type: 'scatter',
|
| 268 |
data: {
|
| 269 |
datasets: [
|
|
|
|
| 313 |
}
|
| 314 |
}
|
| 315 |
}
|
| 316 |
+
}, 'Linear Regression Chart');
|
| 317 |
}
|
| 318 |
|
| 319 |
// Gradient Descent Visualization
|
|
|
|
| 429 |
const ctx = canvas.getContext('2d');
|
| 430 |
const lossData = state.gdIterations.map((iter, i) => ({ x: i + 1, y: iter.loss }));
|
| 431 |
|
| 432 |
+
gdChart = safeCreateChart(ctx, {
|
| 433 |
type: 'line',
|
| 434 |
data: {
|
| 435 |
datasets: [{
|
|
|
|
| 474 |
});
|
| 475 |
}
|
| 476 |
|
| 477 |
+
// Safe chart creation with error handling
|
| 478 |
+
function safeCreateChart(ctx, config, chartName) {
|
| 479 |
+
try {
|
| 480 |
+
if (!ctx) {
|
| 481 |
+
console.warn(`Canvas context not found for ${chartName}`);
|
| 482 |
+
return null;
|
| 483 |
+
}
|
| 484 |
+
return new Chart(ctx, config);
|
| 485 |
+
} catch (error) {
|
| 486 |
+
console.error(`Chart creation failed for ${chartName}:`, error);
|
| 487 |
+
// Show fallback message
|
| 488 |
+
if (ctx && ctx.canvas && ctx.canvas.parentElement) {
|
| 489 |
+
ctx.canvas.parentElement.innerHTML = `<p style="color: #ff8c6a; text-align: center; padding: 40px;">Visualization temporarily unavailable. Please refresh the page.</p>`;
|
| 490 |
+
}
|
| 491 |
+
return null;
|
| 492 |
+
}
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
// Initialize everything when DOM is ready
|
| 496 |
function init() {
|
| 497 |
+
initCategories();
|
| 498 |
initSections();
|
| 499 |
initTOCLinks();
|
| 500 |
|
|
|
|
| 560 |
if (!canvas) return;
|
| 561 |
|
| 562 |
const ctx = canvas.getContext('2d');
|
| 563 |
+
if (!ctx) {
|
| 564 |
+
console.warn('Could not get canvas context for svm-basic-canvas');
|
| 565 |
+
return;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
const width = canvas.width = canvas.offsetWidth || 600;
|
| 569 |
const height = canvas.height = 450;
|
| 570 |
|
| 571 |
ctx.clearRect(0, 0, width, height);
|
|
|
|
| 686 |
if (!canvas) return;
|
| 687 |
|
| 688 |
const ctx = canvas.getContext('2d');
|
| 689 |
+
if (!ctx) {
|
| 690 |
+
console.warn('Could not get canvas context for svm-margin-canvas');
|
| 691 |
+
return;
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
const width = canvas.width = canvas.offsetWidth || 600;
|
| 695 |
const height = canvas.height = 450;
|
| 696 |
|
| 697 |
ctx.clearRect(0, 0, width, height);
|
|
|
|
| 812 |
}
|
| 813 |
|
| 814 |
const ctx = canvas.getContext('2d');
|
| 815 |
+
if (!ctx) {
|
| 816 |
+
console.warn('Could not get canvas context for svm-c-canvas');
|
| 817 |
+
return;
|
| 818 |
+
}
|
| 819 |
+
|
| 820 |
+
const width = canvas.width = canvas.offsetWidth || 600;
|
| 821 |
const height = canvas.height = 450;
|
| 822 |
|
| 823 |
ctx.clearRect(0, 0, width, height);
|
|
|
|
| 995 |
if (!canvas) return;
|
| 996 |
|
| 997 |
const ctx = canvas.getContext('2d');
|
| 998 |
+
if (!ctx) {
|
| 999 |
+
console.warn('Could not get canvas context for svm-train-canvas');
|
| 1000 |
+
return;
|
| 1001 |
+
}
|
| 1002 |
+
|
| 1003 |
+
const width = canvas.width = canvas.offsetWidth || 600;
|
| 1004 |
const height = canvas.height = 450;
|
| 1005 |
|
| 1006 |
ctx.clearRect(0, 0, width, height);
|
|
|
|
| 2528 |
}
|
| 2529 |
}
|
| 2530 |
}
|
| 2531 |
+
}, 'Elbow Chart');
|
| 2532 |
}
|
| 2533 |
|
| 2534 |
function drawCVKHeatmap() {
|
|
|
|
| 2923 |
|
| 2924 |
const ctx = canvas.getContext('2d');
|
| 2925 |
|
| 2926 |
+
categoricalNBChart = safeCreateChart(ctx, {
|
| 2927 |
type: 'bar',
|
| 2928 |
data: {
|
| 2929 |
labels: ['P(Yes|Rainy,Hot)', 'P(No|Rainy,Hot)'],
|
|
|
|
| 2975 |
}
|
| 2976 |
}
|
| 2977 |
}
|
| 2978 |
+
}, 'Categorical Naive Bayes Chart');
|
| 2979 |
}
|
| 2980 |
|
| 2981 |
function drawGaussianNB() {
|
|
|
|
| 3157 |
compCanvas.style.marginTop = '20px';
|
| 3158 |
canvas.parentElement.appendChild(compCanvas);
|
| 3159 |
|
| 3160 |
+
bayesComparisonChart = safeCreateChart(compCanvas.getContext('2d'), {
|
| 3161 |
type: 'bar',
|
| 3162 |
data: {
|
| 3163 |
labels: ['Spam Probability', 'Not-Spam Probability'],
|
|
|
|
| 3193 |
}
|
| 3194 |
}
|
| 3195 |
}
|
| 3196 |
+
}, 'Bayes Comparison Chart');
|
| 3197 |
+
if (bayesComparisonChart) compCanvas.style.height = '150px';
|
| 3198 |
}
|
| 3199 |
}
|
| 3200 |
|
|
|
|
| 3313 |
ctx.fillText('Example: Email with "free" + link → SPAM', 40, height - 20);
|
| 3314 |
}
|
| 3315 |
|
| 3316 |
+
function drawSplitComparison() {
|
| 3317 |
+
const canvas = document.getElementById('split-comparison');
|
| 3318 |
+
if (!canvas) return;
|
| 3319 |
+
|
| 3320 |
+
const ctx = canvas.getContext('2d');
|
| 3321 |
+
const width = canvas.width = canvas.offsetWidth;
|
| 3322 |
+
const height = canvas.height = 400;
|
| 3323 |
+
|
| 3324 |
+
ctx.clearRect(0, 0, width, height);
|
| 3325 |
+
ctx.fillStyle = '#1a2332';
|
| 3326 |
+
ctx.fillRect(0, 0, width, height);
|
| 3327 |
+
|
| 3328 |
+
const splits = [
|
| 3329 |
+
{ name: 'Split A: "Contains FREE"', ig: 0.034, color: '#ff8c6a' },
|
| 3330 |
+
{ name: 'Split B: "Has Link"', ig: 0.156, color: '#7ef0d4' },
|
| 3331 |
+
{ name: 'Split C: "Urgent"', ig: 0.089, color: '#ffb490' }
|
| 3332 |
+
];
|
| 3333 |
+
|
| 3334 |
+
const padding = 60;
|
| 3335 |
+
const barHeight = 60;
|
| 3336 |
+
const maxWidth = width - 2 * padding - 200;
|
| 3337 |
+
const maxIG = Math.max(...splits.map(s => s.ig));
|
| 3338 |
+
|
| 3339 |
+
splits.forEach((split, i) => {
|
| 3340 |
+
const y = 80 + i * (barHeight + 40);
|
| 3341 |
+
const barWidth = (split.ig / maxIG) * maxWidth;
|
| 3342 |
+
|
| 3343 |
+
// Bar
|
| 3344 |
+
ctx.fillStyle = split.color;
|
| 3345 |
+
ctx.fillRect(padding, y, barWidth, barHeight);
|
| 3346 |
+
|
| 3347 |
+
// Border
|
| 3348 |
+
ctx.strokeStyle = split.color;
|
| 3349 |
+
ctx.lineWidth = 2;
|
| 3350 |
+
ctx.strokeRect(padding, y, barWidth, barHeight);
|
| 3351 |
+
|
| 3352 |
+
// Label
|
| 3353 |
+
ctx.fillStyle = '#e8eef6';
|
| 3354 |
+
ctx.font = 'bold 13px sans-serif';
|
| 3355 |
+
ctx.textAlign = 'left';
|
| 3356 |
+
ctx.fillText(split.name, padding, y - 10);
|
| 3357 |
+
|
| 3358 |
+
// Value
|
| 3359 |
+
ctx.fillStyle = '#1a2332';
|
| 3360 |
+
ctx.font = 'bold 16px sans-serif';
|
| 3361 |
+
ctx.textAlign = 'center';
|
| 3362 |
+
ctx.fillText(`IG = ${split.ig.toFixed(3)}`, padding + barWidth / 2, y + barHeight / 2 + 6);
|
| 3363 |
+
});
|
| 3364 |
+
|
| 3365 |
+
// Winner
|
| 3366 |
+
ctx.fillStyle = '#7ef0d4';
|
| 3367 |
+
ctx.font = 'bold 16px sans-serif';
|
| 3368 |
+
ctx.textAlign = 'center';
|
| 3369 |
+
ctx.fillText('✓ Best split: Highest Information Gain!', width / 2, height - 30);
|
| 3370 |
+
|
| 3371 |
+
// Title
|
| 3372 |
+
ctx.fillStyle = '#7ef0d4';
|
| 3373 |
+
ctx.font = 'bold 16px sans-serif';
|
| 3374 |
+
ctx.fillText('Comparing Split Quality', width / 2, 40);
|
| 3375 |
+
}
|
| 3376 |
+
|
| 3377 |
function drawEntropyViz() {
|
| 3378 |
const canvas = document.getElementById('entropy-viz');
|
| 3379 |
if (!canvas) return;
|
|
|
|
| 3517 |
ctx.fillText('Comparing Split Quality', width / 2, 40);
|
| 3518 |
}
|
| 3519 |
|
| 3520 |
+
function drawEntropyViz() {
|
| 3521 |
+
const canvas = document.getElementById('entropy-viz');
|
| 3522 |
+
if (!canvas) return;
|
| 3523 |
+
|
| 3524 |
+
const ctx = canvas.getContext('2d');
|
| 3525 |
+
const width = canvas.width = canvas.offsetWidth;
|
| 3526 |
+
const height = canvas.height = 400;
|
| 3527 |
+
|
| 3528 |
+
ctx.clearRect(0, 0, width, height);
|
| 3529 |
+
ctx.fillStyle = '#1a2332';
|
| 3530 |
+
ctx.fillRect(0, 0, width, height);
|
| 3531 |
+
|
| 3532 |
+
const padding = 60;
|
| 3533 |
+
const chartWidth = width - 2 * padding;
|
| 3534 |
+
const chartHeight = height - 2 * padding;
|
| 3535 |
+
|
| 3536 |
+
// Draw entropy curve
|
| 3537 |
+
ctx.strokeStyle = '#6aa9ff';
|
| 3538 |
+
ctx.lineWidth = 3;
|
| 3539 |
+
ctx.beginPath();
|
| 3540 |
+
for (let p = 0.01; p <= 0.99; p += 0.01) {
|
| 3541 |
+
const entropy = -p * Math.log2(p) - (1 - p) * Math.log2(1 - p);
|
| 3542 |
+
const x = padding + p * chartWidth;
|
| 3543 |
+
const y = height - padding - entropy * chartHeight;
|
| 3544 |
+
if (p === 0.01) ctx.moveTo(x, y);
|
| 3545 |
+
else ctx.lineTo(x, y);
|
| 3546 |
+
}
|
| 3547 |
+
ctx.stroke();
|
| 3548 |
+
|
| 3549 |
+
// Mark key points
|
| 3550 |
+
const points = [
|
| 3551 |
+
{ p: 0.1, label: 'Pure\n(low)' },
|
| 3552 |
+
{ p: 0.5, label: 'Maximum\n(high)' },
|
| 3553 |
+
{ p: 0.9, label: 'Pure\n(low)' }
|
| 3554 |
+
];
|
| 3555 |
+
|
| 3556 |
+
points.forEach(point => {
|
| 3557 |
+
const entropy = -point.p * Math.log2(point.p) - (1 - point.p) * Math.log2(1 - point.p);
|
| 3558 |
+
const x = padding + point.p * chartWidth;
|
| 3559 |
+
const y = height - padding - entropy * chartHeight;
|
| 3560 |
+
|
| 3561 |
+
ctx.fillStyle = '#7ef0d4';
|
| 3562 |
+
ctx.beginPath();
|
| 3563 |
+
ctx.arc(x, y, 6, 0, 2 * Math.PI);
|
| 3564 |
+
ctx.fill();
|
| 3565 |
+
|
| 3566 |
+
ctx.fillStyle = '#7ef0d4';
|
| 3567 |
+
ctx.font = '11px sans-serif';
|
| 3568 |
+
ctx.textAlign = 'center';
|
| 3569 |
+
const lines = point.label.split('\n');
|
| 3570 |
+
lines.forEach((line, i) => {
|
| 3571 |
+
ctx.fillText(line, x, y - 15 - (lines.length - 1 - i) * 12);
|
| 3572 |
+
});
|
| 3573 |
+
});
|
| 3574 |
+
|
| 3575 |
+
// Axes
|
| 3576 |
+
ctx.strokeStyle = '#2a3544';
|
| 3577 |
+
ctx.lineWidth = 2;
|
| 3578 |
+
ctx.beginPath();
|
| 3579 |
+
ctx.moveTo(padding, padding);
|
| 3580 |
+
ctx.lineTo(padding, height - padding);
|
| 3581 |
+
ctx.lineTo(width - padding, height - padding);
|
| 3582 |
+
ctx.stroke();
|
| 3583 |
+
|
| 3584 |
+
// Labels
|
| 3585 |
+
ctx.fillStyle = '#a9b4c2';
|
| 3586 |
+
ctx.font = '12px sans-serif';
|
| 3587 |
+
ctx.textAlign = 'center';
|
| 3588 |
+
ctx.fillText('Proportion of Positive Class (p)', width / 2, height - 20);
|
| 3589 |
+
ctx.save();
|
| 3590 |
+
ctx.translate(20, height / 2);
|
| 3591 |
+
ctx.rotate(-Math.PI / 2);
|
| 3592 |
+
ctx.fillText('Entropy H(p)', 0, 0);
|
| 3593 |
+
ctx.restore();
|
| 3594 |
+
|
| 3595 |
+
// Title
|
| 3596 |
+
ctx.fillStyle = '#7ef0d4';
|
| 3597 |
+
ctx.font = 'bold 16px sans-serif';
|
| 3598 |
+
ctx.textAlign = 'center';
|
| 3599 |
+
ctx.fillText('Entropy: Measuring Disorder', width / 2, 30);
|
| 3600 |
+
}
|
| 3601 |
+
|
| 3602 |
function drawTreeBoundary() {
|
| 3603 |
const canvas = document.getElementById('tree-boundary');
|
| 3604 |
if (!canvas) return;
|
|
|
|
| 3798 |
ctx.fillText('Bagging: Bootstrap Aggregating', width / 2, 30);
|
| 3799 |
}
|
| 3800 |
|
| 3801 |
+
|
| 3802 |
+
|
| 3803 |
function drawBoostingViz() {
|
| 3804 |
const canvas = document.getElementById('boosting-viz');
|
| 3805 |
if (!canvas) return;
|
|
|
|
| 4175 |
const kValues = [1, 2, 3, 4, 5];
|
| 4176 |
const wcssValues = [50, 18, 10, 8, 7];
|
| 4177 |
|
| 4178 |
+
kmeansElbowChart = safeCreateChart(ctx, {
|
| 4179 |
type: 'line',
|
| 4180 |
data: {
|
| 4181 |
labels: kValues,
|
|
|
|
| 4238 |
}
|
| 4239 |
}
|
| 4240 |
}
|
| 4241 |
+
}, 'K-means Elbow Chart');
|
| 4242 |
}
|
| 4243 |
|
| 4244 |
+
// Topic 18: Algorithm Comparison
|
| 4245 |
+
let comparisonState = {
|
| 4246 |
+
selectedAlgorithms: [],
|
| 4247 |
+
algorithmData: {
|
| 4248 |
+
'Linear Regression': {
|
| 4249 |
+
category: 'Supervised - Regression',
|
| 4250 |
+
speed: 5, accuracy: 3, dataRequired: 1, interpretability: 5, scalability: 3,
|
| 4251 |
+
featureScaling: 'Required', nonLinear: 'No', trainingTime: 'Fast', memoryUsage: 'Low',
|
| 4252 |
+
bestFor: 'Linear trends, forecasting',
|
| 4253 |
+
pros: ['Very fast', 'Highly interpretable', 'Works with little data', 'No tuning needed'],
|
| 4254 |
+
cons: ['Assumes linearity', 'Sensitive to outliers', 'No complex patterns'],
|
| 4255 |
+
useCases: { regression: 5, classification: 0, clustering: 0, speed: 5, interpretability: 5 }
|
| 4256 |
+
},
|
| 4257 |
+
'Logistic Regression': {
|
| 4258 |
+
category: 'Supervised - Classification',
|
| 4259 |
+
speed: 5, accuracy: 4, dataRequired: 2, interpretability: 4, scalability: 4,
|
| 4260 |
+
featureScaling: 'Required', nonLinear: 'No', trainingTime: 'Fast', memoryUsage: 'Low',
|
| 4261 |
+
bestFor: 'Binary classification, probabilities',
|
| 4262 |
+
pros: ['Fast', 'Probabilistic output', 'Interpretable', 'Works well'],
|
| 4263 |
+
cons: ['Binary only', 'Assumes linearity', 'Limited complexity'],
|
| 4264 |
+
useCases: { regression: 0, classification: 5, clustering: 0, speed: 5, interpretability: 4 }
|
| 4265 |
+
},
|
| 4266 |
+
'SVM': {
|
| 4267 |
+
category: 'Supervised - Classification',
|
| 4268 |
+
speed: 2, accuracy: 5, dataRequired: 2, interpretability: 2, scalability: 2,
|
| 4269 |
+
featureScaling: 'Required', nonLinear: 'Yes', trainingTime: 'Slow', memoryUsage: 'Medium',
|
| 4270 |
+
bestFor: 'High accuracy, complex boundaries',
|
| 4271 |
+
pros: ['Very high accuracy', 'Handles non-linear', 'Effective in high dims'],
|
| 4272 |
+
cons: ['Slow training', 'Hard to interpret', 'Needs tuning'],
|
| 4273 |
+
useCases: { regression: 2, classification: 5, clustering: 0, speed: 2, interpretability: 2 }
|
| 4274 |
+
},
|
| 4275 |
+
'KNN': {
|
| 4276 |
+
category: 'Supervised - Classification',
|
| 4277 |
+
speed: 1, accuracy: 4, dataRequired: 3, interpretability: 3, scalability: 1,
|
| 4278 |
+
featureScaling: 'Required', nonLinear: 'Yes', trainingTime: 'None', memoryUsage: 'High',
|
| 4279 |
+
bestFor: 'Local patterns, small datasets',
|
| 4280 |
+
pros: ['Simple', 'No training', 'Handles non-linear'],
|
| 4281 |
+
cons: ['Very slow prediction', 'Needs lots of memory', 'Needs scaling'],
|
| 4282 |
+
useCases: { regression: 3, classification: 4, clustering: 3, speed: 1, interpretability: 3 }
|
| 4283 |
+
},
|
| 4284 |
+
'Naive Bayes': {
|
| 4285 |
+
category: 'Supervised - Classification',
|
| 4286 |
+
speed: 5, accuracy: 3, dataRequired: 2, interpretability: 5, scalability: 5,
|
| 4287 |
+
featureScaling: 'Not needed', nonLinear: 'Yes', trainingTime: 'Fast', memoryUsage: 'Low',
|
| 4288 |
+
bestFor: 'Quick models, text classification',
|
| 4289 |
+
pros: ['Very fast', 'Interpretable', 'Works with little data'],
|
| 4290 |
+
cons: ['Independence assumption wrong', 'Often biased', 'Limited accuracy'],
|
| 4291 |
+
useCases: { regression: 2, classification: 4, clustering: 0, speed: 5, interpretability: 5 }
|
| 4292 |
+
},
|
| 4293 |
+
'Decision Trees': {
|
| 4294 |
+
category: 'Supervised - Classification',
|
| 4295 |
+
speed: 3, accuracy: 4, dataRequired: 2, interpretability: 5, scalability: 3,
|
| 4296 |
+
featureScaling: 'Not needed', nonLinear: 'Yes', trainingTime: 'Medium', memoryUsage: 'Low',
|
| 4297 |
+
bestFor: 'Interpretability, complex decisions',
|
| 4298 |
+
pros: ['Very interpretable', 'No scaling needed', 'Handles non-linear'],
|
| 4299 |
+
cons: ['Prone to overfitting', 'Unstable', 'Biased to dominant class'],
|
| 4300 |
+
useCases: { regression: 3, classification: 4, clustering: 0, speed: 3, interpretability: 5 }
|
| 4301 |
+
},
|
| 4302 |
+
'Random Forest': {
|
| 4303 |
+
category: 'Supervised - Classification',
|
| 4304 |
+
speed: 2, accuracy: 5, dataRequired: 3, interpretability: 3, scalability: 3,
|
| 4305 |
+
featureScaling: 'Not needed', nonLinear: 'Yes', trainingTime: 'Slow', memoryUsage: 'Medium',
|
| 4306 |
+
bestFor: 'High accuracy with complex data',
|
| 4307 |
+
pros: ['Very high accuracy', 'No scaling', 'Handles non-linear'],
|
| 4308 |
+
cons: ['Slow', 'Less interpretable', 'Black box'],
|
| 4309 |
+
useCases: { regression: 3, classification: 5, clustering: 0, speed: 3, interpretability: 2 }
|
| 4310 |
+
},
|
| 4311 |
+
'K-means': {
|
| 4312 |
+
category: 'Unsupervised - Clustering',
|
| 4313 |
+
speed: 4, accuracy: 3, dataRequired: 3, interpretability: 4, scalability: 4,
|
| 4314 |
+
featureScaling: 'Required', nonLinear: 'No', trainingTime: 'Medium', memoryUsage: 'Low',
|
| 4315 |
+
bestFor: 'Customer segmentation, grouping',
|
| 4316 |
+
pros: ['Fast', 'Simple', 'Scalable'],
|
| 4317 |
+
cons: ['Need to specify K', 'Sensitive to init', 'Assumes spherical'],
|
| 4318 |
+
useCases: { regression: 0, classification: 0, clustering: 5, speed: 4, interpretability: 4 }
|
| 4319 |
+
},
|
| 4320 |
+
'PCA': {
|
| 4321 |
+
category: 'Unsupervised - Dimensionality Reduction',
|
| 4322 |
+
speed: 3, accuracy: 4, dataRequired: 2, interpretability: 2, scalability: 4,
|
| 4323 |
+
featureScaling: 'Required', nonLinear: 'No', trainingTime: 'Medium', memoryUsage: 'Medium',
|
| 4324 |
+
bestFor: 'High-dimensional data reduction',
|
| 4325 |
+
pros: ['Reduces dimensions', 'Preserves variance', 'Fast after trained'],
|
| 4326 |
+
cons: ['Components not interpretable', 'Linear only', 'Assumes normality'],
|
| 4327 |
+
useCases: { regression: 0, classification: 0, clustering: 0, speed: 4, interpretability: 2 }
|
| 4328 |
+
}
|
| 4329 |
+
}
|
| 4330 |
+
};
|
| 4331 |
+
|
| 4332 |
function initAlgorithmComparison() {
|
| 4333 |
+
const container = document.getElementById('algorithm-checkboxes');
|
| 4334 |
+
if (!container || container.dataset.initialized) return;
|
| 4335 |
+
container.dataset.initialized = 'true';
|
| 4336 |
+
|
| 4337 |
+
populateAlgorithmCheckboxes();
|
| 4338 |
+
initComparisonListeners();
|
| 4339 |
+
initQuiz();
|
| 4340 |
+
}
|
| 4341 |
+
|
| 4342 |
+
function populateAlgorithmCheckboxes() {
|
| 4343 |
+
const container = document.getElementById('algorithm-checkboxes');
|
| 4344 |
+
if (!container) return;
|
| 4345 |
+
|
| 4346 |
+
const categoryRadios = document.querySelectorAll('input[name="category"]');
|
| 4347 |
+
|
| 4348 |
+
function updateCheckboxes() {
|
| 4349 |
+
const selectedCategory = document.querySelector('input[name="category"]:checked')?.value || 'all';
|
| 4350 |
+
container.innerHTML = '';
|
| 4351 |
+
|
| 4352 |
+
Object.keys(comparisonState.algorithmData).forEach(name => {
|
| 4353 |
+
const algo = comparisonState.algorithmData[name];
|
| 4354 |
+
const category = algo.category.toLowerCase();
|
| 4355 |
+
|
| 4356 |
+
if (selectedCategory === 'all' ||
|
| 4357 |
+
(selectedCategory === 'supervised' && category.includes('supervised')) ||
|
| 4358 |
+
(selectedCategory === 'unsupervised' && category.includes('unsupervised'))) {
|
| 4359 |
+
|
| 4360 |
+
const label = document.createElement('label');
|
| 4361 |
+
label.style.display = 'flex';
|
| 4362 |
+
label.style.alignItems = 'center';
|
| 4363 |
+
label.style.gap = '8px';
|
| 4364 |
+
label.style.cursor = 'pointer';
|
| 4365 |
+
label.style.padding = '8px';
|
| 4366 |
+
label.style.borderRadius = '6px';
|
| 4367 |
+
label.style.transition = 'background 0.2s';
|
| 4368 |
+
|
| 4369 |
+
const checkbox = document.createElement('input');
|
| 4370 |
+
checkbox.type = 'checkbox';
|
| 4371 |
+
checkbox.value = name;
|
| 4372 |
+
checkbox.addEventListener('change', updateSelection);
|
| 4373 |
+
|
| 4374 |
+
const text = document.createTextNode(name);
|
| 4375 |
+
|
| 4376 |
+
label.appendChild(checkbox);
|
| 4377 |
+
label.appendChild(text);
|
| 4378 |
+
label.addEventListener('mouseenter', () => label.style.background = 'var(--color-secondary)');
|
| 4379 |
+
label.addEventListener('mouseleave', () => label.style.background = 'transparent');
|
| 4380 |
+
|
| 4381 |
+
container.appendChild(label);
|
| 4382 |
+
}
|
| 4383 |
+
});
|
| 4384 |
+
}
|
| 4385 |
+
|
| 4386 |
+
categoryRadios.forEach(radio => radio.addEventListener('change', updateCheckboxes));
|
| 4387 |
+
updateCheckboxes();
|
| 4388 |
+
}
|
| 4389 |
+
|
| 4390 |
+
function updateSelection() {
|
| 4391 |
+
const checkboxes = document.querySelectorAll('#algorithm-checkboxes input[type="checkbox"]:checked');
|
| 4392 |
+
comparisonState.selectedAlgorithms = Array.from(checkboxes).map(cb => cb.value);
|
| 4393 |
+
|
| 4394 |
+
const count = comparisonState.selectedAlgorithms.length;
|
| 4395 |
+
const countEl = document.getElementById('selection-count');
|
| 4396 |
+
const compareBtn = document.getElementById('compare-btn');
|
| 4397 |
+
|
| 4398 |
+
if (countEl) {
|
| 4399 |
+
countEl.textContent = `Selected: ${count} algorithm${count !== 1 ? 's' : ''}`;
|
| 4400 |
+
countEl.style.color = count >= 2 && count <= 5 ? 'var(--color-success)' : 'var(--color-error)';
|
| 4401 |
+
}
|
| 4402 |
+
|
| 4403 |
+
if (compareBtn) {
|
| 4404 |
+
compareBtn.disabled = count < 2 || count > 5;
|
| 4405 |
+
}
|
| 4406 |
+
}
|
| 4407 |
+
|
| 4408 |
+
function initComparisonListeners() {
|
| 4409 |
+
const compareBtn = document.getElementById('compare-btn');
|
| 4410 |
+
if (compareBtn) {
|
| 4411 |
+
compareBtn.addEventListener('click', showComparison);
|
| 4412 |
+
}
|
| 4413 |
+
|
| 4414 |
+
const viewBtns = document.querySelectorAll('.view-btn');
|
| 4415 |
+
viewBtns.forEach(btn => {
|
| 4416 |
+
btn.addEventListener('click', () => {
|
| 4417 |
+
viewBtns.forEach(b => b.classList.remove('active'));
|
| 4418 |
+
btn.classList.add('active');
|
| 4419 |
+
|
| 4420 |
+
const view = btn.dataset.view;
|
| 4421 |
+
document.querySelectorAll('.comparison-view').forEach(v => v.style.display = 'none');
|
| 4422 |
+
const targetView = document.getElementById(`view-${view}`);
|
| 4423 |
+
if (targetView) targetView.style.display = 'block';
|
| 4424 |
+
});
|
| 4425 |
+
});
|
| 4426 |
+
}
|
| 4427 |
+
|
| 4428 |
+
function showComparison() {
|
| 4429 |
+
const resultsDiv = document.getElementById('comparison-results');
|
| 4430 |
+
if (!resultsDiv) return;
|
| 4431 |
+
|
| 4432 |
+
resultsDiv.style.display = 'block';
|
| 4433 |
+
resultsDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
| 4434 |
+
|
| 4435 |
+
renderComparisonTable();
|
| 4436 |
+
renderRadarChart();
|
| 4437 |
+
renderHeatmap();
|
| 4438 |
+
renderUseCaseMatrix();
|
| 4439 |
+
renderDetailedCards();
|
| 4440 |
+
}
|
| 4441 |
+
|
| 4442 |
+
function renderComparisonTable() {
|
| 4443 |
+
const table = document.getElementById('comparison-table');
|
| 4444 |
+
if (!table) return;
|
| 4445 |
+
|
| 4446 |
+
const metrics = [
|
| 4447 |
+
{ key: 'speed', label: 'Speed', format: (v) => '⭐'.repeat(v) },
|
| 4448 |
+
{ key: 'accuracy', label: 'Accuracy', format: (v) => '⭐'.repeat(v) },
|
| 4449 |
+
{ key: 'dataRequired', label: 'Data Required', format: (v) => ['Small', 'Small', 'Medium', 'Large', 'Very Large'][v] },
|
| 4450 |
+
{ key: 'interpretability', label: 'Interpretability', format: (v) => '⭐'.repeat(v) },
|
| 4451 |
+
{ key: 'featureScaling', label: 'Feature Scaling' },
|
| 4452 |
+
{ key: 'nonLinear', label: 'Handles Non-linear' },
|
| 4453 |
+
{ key: 'trainingTime', label: 'Training Time' },
|
| 4454 |
+
{ key: 'memoryUsage', label: 'Memory Usage' },
|
| 4455 |
+
{ key: 'bestFor', label: 'Best For' }
|
| 4456 |
+
];
|
| 4457 |
+
|
| 4458 |
+
let html = '<thead><tr><th>Metric</th>';
|
| 4459 |
+
comparisonState.selectedAlgorithms.forEach(name => {
|
| 4460 |
+
html += `<th>${name}</th>`;
|
| 4461 |
+
});
|
| 4462 |
+
html += '</tr></thead><tbody>';
|
| 4463 |
+
|
| 4464 |
+
metrics.forEach(metric => {
|
| 4465 |
+
html += `<tr><td><strong>${metric.label}</strong></td>`;
|
| 4466 |
+
comparisonState.selectedAlgorithms.forEach(name => {
|
| 4467 |
+
const algo = comparisonState.algorithmData[name];
|
| 4468 |
+
const value = algo[metric.key];
|
| 4469 |
+
const display = metric.format ? metric.format(value) : value;
|
| 4470 |
+
html += `<td>${display}</td>`;
|
| 4471 |
+
});
|
| 4472 |
+
html += '</tr>';
|
| 4473 |
+
});
|
| 4474 |
+
|
| 4475 |
+
html += '</tbody>';
|
| 4476 |
+
table.innerHTML = html;
|
| 4477 |
+
}
|
| 4478 |
+
|
| 4479 |
+
let radarComparisonChart = null;
|
| 4480 |
+
|
| 4481 |
+
function renderRadarChart() {
|
| 4482 |
+
const canvas = document.getElementById('radar-comparison-canvas');
|
| 4483 |
+
if (!canvas) return;
|
| 4484 |
+
|
| 4485 |
+
if (radarComparisonChart) {
|
| 4486 |
+
radarComparisonChart.destroy();
|
| 4487 |
+
radarComparisonChart = null;
|
| 4488 |
+
}
|
| 4489 |
+
|
| 4490 |
+
const ctx = canvas.getContext('2d');
|
| 4491 |
+
canvas.width = canvas.offsetWidth;
|
| 4492 |
+
canvas.height = 500;
|
| 4493 |
+
|
| 4494 |
+
const colors = ['#6aa9ff', '#7ef0d4', '#ff8c6a', '#ffeb3b', '#ffb490'];
|
| 4495 |
+
|
| 4496 |
+
const datasets = comparisonState.selectedAlgorithms.map((name, i) => {
|
| 4497 |
+
const algo = comparisonState.algorithmData[name];
|
| 4498 |
+
return {
|
| 4499 |
+
label: name,
|
| 4500 |
+
data: [algo.speed, algo.accuracy, 5 - algo.dataRequired, algo.interpretability, algo.scalability],
|
| 4501 |
+
borderColor: colors[i],
|
| 4502 |
+
backgroundColor: colors[i] + '33',
|
| 4503 |
+
borderWidth: 2,
|
| 4504 |
+
pointRadius: 4
|
| 4505 |
+
};
|
| 4506 |
+
});
|
| 4507 |
+
|
| 4508 |
+
radarComparisonChart = safeCreateChart(ctx, {
|
| 4509 |
+
type: 'radar',
|
| 4510 |
+
data: {
|
| 4511 |
+
labels: ['Speed', 'Accuracy', 'Data Efficiency', 'Interpretability', 'Scalability'],
|
| 4512 |
+
datasets: datasets
|
| 4513 |
+
},
|
| 4514 |
+
options: {
|
| 4515 |
+
responsive: true,
|
| 4516 |
+
maintainAspectRatio: false,
|
| 4517 |
+
plugins: {
|
| 4518 |
+
legend: {
|
| 4519 |
+
position: 'top',
|
| 4520 |
+
labels: { color: '#a9b4c2', padding: 15 }
|
| 4521 |
+
}
|
| 4522 |
+
},
|
| 4523 |
+
scales: {
|
| 4524 |
+
r: {
|
| 4525 |
+
beginAtZero: true,
|
| 4526 |
+
max: 5,
|
| 4527 |
+
ticks: { color: '#a9b4c2', backdropColor: 'transparent' },
|
| 4528 |
+
grid: { color: '#2a3544' },
|
| 4529 |
+
pointLabels: { color: '#e8eef6', font: { size: 12 } }
|
| 4530 |
+
}
|
| 4531 |
+
}
|
| 4532 |
+
}
|
| 4533 |
+
}, 'Radar Comparison Chart');
|
| 4534 |
+
}
|
| 4535 |
+
|
| 4536 |
+
function renderHeatmap() {
|
| 4537 |
+
const container = document.getElementById('view-heatmap');
|
| 4538 |
+
if (!container) return;
|
| 4539 |
+
|
| 4540 |
+
// Remove canvas, use HTML table instead for 100% browser compatibility
|
| 4541 |
+
const metrics = ['Speed', 'Accuracy', 'Data Efficiency', 'Interpretability', 'Scalability'];
|
| 4542 |
+
const algos = comparisonState.selectedAlgorithms;
|
| 4543 |
+
|
| 4544 |
+
// Helper function to get color based on value
|
| 4545 |
+
function getHeatmapColor(value) {
|
| 4546 |
+
const intensity = value / 5;
|
| 4547 |
+
const r = Math.floor(255 - 149 * intensity);
|
| 4548 |
+
const g = Math.floor(140 + 100 * intensity);
|
| 4549 |
+
const b = Math.floor(106 + 106 * intensity);
|
| 4550 |
+
return `rgb(${r}, ${g}, ${b})`;
|
| 4551 |
+
}
|
| 4552 |
+
|
| 4553 |
+
// Build HTML table heatmap
|
| 4554 |
+
let html = '<h3 style="margin-bottom: 20px; text-align: center; color: #7ef0d4;">Performance Heatmap (Higher is Better)</h3>';
|
| 4555 |
+
html += '<div style="overflow-x: auto;">';
|
| 4556 |
+
html += '<table style="width: 100%; border-collapse: collapse; margin: 20px auto; max-width: 1000px;">';
|
| 4557 |
+
|
| 4558 |
+
// Header row
|
| 4559 |
+
html += '<thead><tr style="background: #2a3544; border-bottom: 2px solid #6aa9ff;">';
|
| 4560 |
+
html += '<th style="padding: 12px; text-align: left; color: #7ef0d4; border: 1px solid #3a4554; min-width: 150px;">Algorithm</th>';
|
| 4561 |
+
metrics.forEach(metric => {
|
| 4562 |
+
html += `<th style="padding: 12px; text-align: center; color: #7ef0d4; border: 1px solid #3a4554; min-width: 80px;">${metric}</th>`;
|
| 4563 |
+
});
|
| 4564 |
+
html += '</tr></thead>';
|
| 4565 |
+
|
| 4566 |
+
// Data rows
|
| 4567 |
+
html += '<tbody>';
|
| 4568 |
+
algos.forEach((name, i) => {
|
| 4569 |
+
const algo = comparisonState.algorithmData[name];
|
| 4570 |
+
const values = [algo.speed, algo.accuracy, 5 - algo.dataRequired, algo.interpretability, algo.scalability];
|
| 4571 |
+
|
| 4572 |
+
html += `<tr style="border-bottom: 1px solid #3a4554;">`;
|
| 4573 |
+
html += `<td style="padding: 12px; font-weight: 600; background: #2a3544; color: #e8eef6; border: 1px solid #3a4554;">${name}</td>`;
|
| 4574 |
+
|
| 4575 |
+
values.forEach((value, j) => {
|
| 4576 |
+
const color = getHeatmapColor(value);
|
| 4577 |
+
const stars = '⭐'.repeat(Math.round(value));
|
| 4578 |
+
html += `<td style="padding: 12px; text-align: center; background: ${color}; border: 1px solid #1a2332; color: #1a2332; font-weight: bold; font-size: 16px;">`;
|
| 4579 |
+
html += `<div style="margin-bottom: 4px;">${value.toFixed(0)}</div>`;
|
| 4580 |
+
html += `<div style="font-size: 12px;">${stars}</div>`;
|
| 4581 |
+
html += `</td>`;
|
| 4582 |
+
});
|
| 4583 |
+
html += '</tr>';
|
| 4584 |
+
});
|
| 4585 |
+
html += '</tbody>';
|
| 4586 |
+
html += '</table>';
|
| 4587 |
+
html += '</div>';
|
| 4588 |
+
|
| 4589 |
+
// Legend
|
| 4590 |
+
html += '<div style="text-align: center; margin-top: 24px; padding: 16px; background: var(--color-bg-2); border-radius: 8px;">';
|
| 4591 |
+
html += '<strong style="color: #e8eef6;">Legend:</strong> ';
|
| 4592 |
+
html += '<span style="margin-left: 16px;">🔴 Low (1-2)</span> ';
|
| 4593 |
+
html += '<span style="margin-left: 16px;">🟡 Medium (3)</span> ';
|
| 4594 |
+
html += '<span style="margin-left: 16px;">🟢 High (4-5)</span>';
|
| 4595 |
+
html += '</div>';
|
| 4596 |
+
|
| 4597 |
+
// Find the canvas and replace with our HTML
|
| 4598 |
+
const oldCanvas = container.querySelector('#heatmap-canvas');
|
| 4599 |
+
if (oldCanvas) {
|
| 4600 |
+
oldCanvas.parentElement.innerHTML = html;
|
| 4601 |
+
} else {
|
| 4602 |
+
container.innerHTML = html;
|
| 4603 |
+
}
|
| 4604 |
+
}
|
| 4605 |
+
|
| 4606 |
+
function renderUseCaseMatrix() {
|
| 4607 |
+
const table = document.getElementById('matrix-table');
|
| 4608 |
+
if (!table) return;
|
| 4609 |
+
|
| 4610 |
+
const useCases = [
|
| 4611 |
+
{ key: 'regression', label: 'Regression' },
|
| 4612 |
+
{ key: 'classification', label: 'Classification' },
|
| 4613 |
+
{ key: 'clustering', label: 'Clustering' },
|
| 4614 |
+
{ key: 'speed', label: 'Speed' },
|
| 4615 |
+
{ key: 'interpretability', label: 'Interpretability' }
|
| 4616 |
+
];
|
| 4617 |
+
|
| 4618 |
+
let html = '<thead><tr><th>Use Case</th>';
|
| 4619 |
+
comparisonState.selectedAlgorithms.forEach(name => {
|
| 4620 |
+
html += `<th>${name}</th>`;
|
| 4621 |
+
});
|
| 4622 |
+
html += '</tr></thead><tbody>';
|
| 4623 |
+
|
| 4624 |
+
useCases.forEach(useCase => {
|
| 4625 |
+
html += `<tr><td><strong>${useCase.label}</strong></td>`;
|
| 4626 |
+
comparisonState.selectedAlgorithms.forEach(name => {
|
| 4627 |
+
const algo = comparisonState.algorithmData[name];
|
| 4628 |
+
const value = algo.useCases[useCase.key];
|
| 4629 |
+
const check = '✓'.repeat(value);
|
| 4630 |
+
html += `<td style="color: ${value > 3 ? 'var(--color-success)' : value > 0 ? 'var(--color-warning)' : 'var(--color-error)'}">${check || '✗'}</td>`;
|
| 4631 |
+
});
|
| 4632 |
+
html += '</tr>';
|
| 4633 |
+
});
|
| 4634 |
+
|
| 4635 |
+
html += '</tbody>';
|
| 4636 |
+
table.innerHTML = html;
|
| 4637 |
+
}
|
| 4638 |
+
|
| 4639 |
+
function renderDetailedCards() {
|
| 4640 |
+
const container = document.getElementById('detailed-cards');
|
| 4641 |
+
if (!container) return;
|
| 4642 |
+
|
| 4643 |
+
let html = '<h3 style="margin-bottom: 24px; text-align: center;">Detailed Comparison</h3>';
|
| 4644 |
+
html += '<div style="display: grid; gap: 24px;">';
|
| 4645 |
+
|
| 4646 |
+
comparisonState.selectedAlgorithms.forEach(name => {
|
| 4647 |
+
const algo = comparisonState.algorithmData[name];
|
| 4648 |
+
html += `
|
| 4649 |
+
<div class="info-card" style="background: var(--color-bg-1); padding: 24px;">
|
| 4650 |
+
<h4 style="font-size: 20px; margin-bottom: 16px; color: var(--color-primary);">${name}</h4>
|
| 4651 |
+
<p style="margin-bottom: 12px; color: var(--color-text-secondary);">${algo.category}</p>
|
| 4652 |
+
|
| 4653 |
+
<div style="margin: 20px 0;">
|
| 4654 |
+
<strong style="color: var(--color-success);">✓ Pros:</strong>
|
| 4655 |
+
<ul style="margin: 8px 0 0 20px; color: var(--color-text);">
|
| 4656 |
+
${algo.pros.map(p => `<li>${p}</li>`).join('')}
|
| 4657 |
+
</ul>
|
| 4658 |
+
</div>
|
| 4659 |
+
|
| 4660 |
+
<div style="margin: 20px 0;">
|
| 4661 |
+
<strong style="color: var(--color-error);">✗ Cons:</strong>
|
| 4662 |
+
<ul style="margin: 8px 0 0 20px; color: var(--color-text);">
|
| 4663 |
+
${algo.cons.map(c => `<li>${c}</li>`).join('')}
|
| 4664 |
+
</ul>
|
| 4665 |
+
</div>
|
| 4666 |
+
|
| 4667 |
+
<div style="padding: 12px; background: var(--color-secondary); border-radius: 6px; margin-top: 16px;">
|
| 4668 |
+
<strong style="color: var(--color-text);">⚡ Best For:</strong> ${algo.bestFor}
|
| 4669 |
+
</div>
|
| 4670 |
+
</div>
|
| 4671 |
+
`;
|
| 4672 |
+
});
|
| 4673 |
+
|
| 4674 |
+
html += '</div>';
|
| 4675 |
+
container.innerHTML = html;
|
| 4676 |
+
}
|
| 4677 |
+
|
| 4678 |
+
function initQuiz() {
|
| 4679 |
+
const questions = document.querySelectorAll('.quiz-question');
|
| 4680 |
+
const resultDiv = document.getElementById('quiz-result');
|
| 4681 |
+
|
| 4682 |
+
questions.forEach((q, idx) => {
|
| 4683 |
+
const radios = q.querySelectorAll('input[type="radio"]');
|
| 4684 |
+
radios.forEach(radio => {
|
| 4685 |
+
radio.addEventListener('change', () => {
|
| 4686 |
+
if (idx < questions.length - 1) {
|
| 4687 |
+
questions[idx + 1].style.display = 'block';
|
| 4688 |
+
}
|
| 4689 |
+
|
| 4690 |
+
if (idx === questions.length - 1) {
|
| 4691 |
+
showQuizResult();
|
| 4692 |
+
}
|
| 4693 |
+
});
|
| 4694 |
+
});
|
| 4695 |
+
});
|
| 4696 |
+
|
| 4697 |
+
function showQuizResult() {
|
| 4698 |
+
const q1 = document.querySelector('input[name="q1"]:checked')?.value;
|
| 4699 |
+
const q2 = document.querySelector('input[name="q2"]:checked')?.value;
|
| 4700 |
+
const q3 = document.querySelector('input[name="q3"]:checked')?.value;
|
| 4701 |
+
const q4 = document.querySelector('input[name="q4"]:checked')?.value;
|
| 4702 |
+
|
| 4703 |
+
let recommendation = '';
|
| 4704 |
+
let alternatives = [];
|
| 4705 |
+
|
| 4706 |
+
if (q1 === 'no') {
|
| 4707 |
+
recommendation = 'K-means';
|
| 4708 |
+
alternatives = ['PCA', 'DBSCAN'];
|
| 4709 |
+
} else if (q2 === 'numbers') {
|
| 4710 |
+
if (q3 === 'little') {
|
| 4711 |
+
recommendation = 'Linear Regression';
|
| 4712 |
+
alternatives = ['Decision Trees'];
|
| 4713 |
+
} else {
|
| 4714 |
+
recommendation = 'Random Forest';
|
| 4715 |
+
alternatives = ['XGBoost', 'Linear Regression'];
|
| 4716 |
+
}
|
| 4717 |
+
} else if (q2 === 'categories') {
|
| 4718 |
+
if (q4 === 'very') {
|
| 4719 |
+
recommendation = 'Decision Trees';
|
| 4720 |
+
alternatives = ['Logistic Regression', 'Naive Bayes'];
|
| 4721 |
+
} else if (q3 === 'little') {
|
| 4722 |
+
recommendation = 'Naive Bayes';
|
| 4723 |
+
alternatives = ['Logistic Regression'];
|
| 4724 |
+
} else {
|
| 4725 |
+
recommendation = 'Random Forest';
|
| 4726 |
+
alternatives = ['SVM', 'XGBoost'];
|
| 4727 |
+
}
|
| 4728 |
+
} else {
|
| 4729 |
+
recommendation = 'K-means';
|
| 4730 |
+
alternatives = ['PCA'];
|
| 4731 |
+
}
|
| 4732 |
+
|
| 4733 |
+
if (resultDiv) {
|
| 4734 |
+
resultDiv.style.display = 'block';
|
| 4735 |
+
resultDiv.innerHTML = `
|
| 4736 |
+
<h4 style="font-size: 18px; color: var(--color-success); margin-bottom: 12px;">🎯 Recommendation: ${recommendation}</h4>
|
| 4737 |
+
<p style="margin-bottom: 12px;">Based on your answers, <strong>${recommendation}</strong> is the best fit for your use case.</p>
|
| 4738 |
+
<p style="margin-bottom: 8px;"><strong>Other good choices:</strong></p>
|
| 4739 |
+
<ul style="margin-left: 20px;">
|
| 4740 |
+
${alternatives.map(a => `<li>${a}</li>`).join('')}
|
| 4741 |
+
</ul>
|
| 4742 |
+
`;
|
| 4743 |
+
resultDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
| 4744 |
+
}
|
| 4745 |
+
}
|
| 4746 |
}
|
| 4747 |
|
| 4748 |
function drawDecisionFlowchart() {
|
ml_complete-all-topics/index.html
CHANGED
|
@@ -450,6 +450,30 @@ canvas {
|
|
| 450 |
margin-right: 8px;
|
| 451 |
}
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
/* Responsive */
|
| 454 |
@media (max-width: 1024px) {
|
| 455 |
.toc-sidebar {
|
|
@@ -485,35 +509,88 @@ canvas {
|
|
| 485 |
<p class="toc-subtitle">Complete Learning Guide</p>
|
| 486 |
</div>
|
| 487 |
<nav class="toc-nav">
|
| 488 |
-
<a href="#intro" class="toc-link">
|
| 489 |
-
|
| 490 |
-
<
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
</nav>
|
| 508 |
</aside>
|
| 509 |
|
| 510 |
<!-- Main Content Area -->
|
| 511 |
<main class="content-main">
|
| 512 |
<div class="content-header">
|
| 513 |
-
<h1>Machine Learning:
|
| 514 |
-
<p>
|
|
|
|
| 515 |
</div>
|
| 516 |
|
|
|
|
|
|
|
|
|
|
| 517 |
<!-- Section 1: Introduction to Machine Learning -->
|
| 518 |
<div class="section" id="intro">
|
| 519 |
<div class="section-header">
|
|
@@ -523,6 +600,39 @@ canvas {
|
|
| 523 |
<div class="section-body">
|
| 524 |
<p>Machine Learning is teaching computers to learn from experience, just like humans do. Instead of programming every rule, we let the computer discover patterns in data and make decisions on its own.</p>
|
| 525 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
<div class="info-card">
|
| 527 |
<div class="info-card-title">Key Concepts</div>
|
| 528 |
<ul class="info-card-list">
|
|
@@ -571,7 +681,7 @@ canvas {
|
|
| 571 |
<!-- Section 2: Linear Regression -->
|
| 572 |
<div class="section" id="linear-regression">
|
| 573 |
<div class="section-header">
|
| 574 |
-
<h2>
|
| 575 |
<button class="section-toggle">▼</button>
|
| 576 |
</div>
|
| 577 |
<div class="section-body">
|
|
@@ -669,7 +779,7 @@ canvas {
|
|
| 669 |
<!-- Section 3: Gradient Descent -->
|
| 670 |
<div class="section" id="gradient-descent">
|
| 671 |
<div class="section-header">
|
| 672 |
-
<h2>
|
| 673 |
<button class="section-toggle">▼</button>
|
| 674 |
</div>
|
| 675 |
<div class="section-body">
|
|
@@ -764,7 +874,7 @@ canvas {
|
|
| 764 |
<!-- Section 4: Logistic Regression -->
|
| 765 |
<div class="section" id="logistic-regression">
|
| 766 |
<div class="section-header">
|
| 767 |
-
<h2>
|
| 768 |
<button class="section-toggle">▼</button>
|
| 769 |
</div>
|
| 770 |
<div class="section-body">
|
|
@@ -906,7 +1016,7 @@ canvas {
|
|
| 906 |
<!-- Section 5: Support Vector Machines (COMPREHENSIVE UPDATE) -->
|
| 907 |
<div class="section" id="svm">
|
| 908 |
<div class="section-header">
|
| 909 |
-
<h2>
|
| 910 |
<button class="section-toggle">▼</button>
|
| 911 |
</div>
|
| 912 |
<div class="section-body">
|
|
@@ -1288,7 +1398,7 @@ canvas {
|
|
| 1288 |
<!-- Section 6: K-Nearest Neighbors -->
|
| 1289 |
<div class="section" id="knn">
|
| 1290 |
<div class="section-header">
|
| 1291 |
-
<h2>
|
| 1292 |
<button class="section-toggle">▼</button>
|
| 1293 |
</div>
|
| 1294 |
<div class="section-body">
|
|
@@ -1412,7 +1522,7 @@ canvas {
|
|
| 1412 |
|
| 1413 |
<div class="section" id="model-evaluation">
|
| 1414 |
<div class="section-header">
|
| 1415 |
-
<h2>
|
| 1416 |
<button class="section-toggle">▼</button>
|
| 1417 |
</div>
|
| 1418 |
<div class="section-body">
|
|
@@ -1865,7 +1975,7 @@ Actual Pos TP FN
|
|
| 1865 |
|
| 1866 |
<div class="section" id="cross-validation">
|
| 1867 |
<div class="section-header">
|
| 1868 |
-
<h2>
|
| 1869 |
<button class="section-toggle">▼</button>
|
| 1870 |
</div>
|
| 1871 |
<div class="section-body">
|
|
@@ -2018,7 +2128,7 @@ Actual Pos TP FN
|
|
| 2018 |
|
| 2019 |
<div class="section" id="preprocessing">
|
| 2020 |
<div class="section-header">
|
| 2021 |
-
<h2>
|
| 2022 |
<button class="section-toggle">▼</button>
|
| 2023 |
</div>
|
| 2024 |
<div class="section-body">
|
|
@@ -2556,7 +2666,7 @@ Actual Pos TP FN
|
|
| 2556 |
<!-- Section 15: Naive Bayes (COMPREHENSIVE WITH MATH) -->
|
| 2557 |
<div class="section" id="naive-bayes">
|
| 2558 |
<div class="section-header">
|
| 2559 |
-
<h2>
|
| 2560 |
<button class="section-toggle">▼</button>
|
| 2561 |
</div>
|
| 2562 |
<div class="section-body">
|
|
@@ -2955,7 +3065,7 @@ Actual Pos TP FN
|
|
| 2955 |
<!-- Section 16: K-means Clustering -->
|
| 2956 |
<div class="section" id="kmeans">
|
| 2957 |
<div class="section-header">
|
| 2958 |
-
<h2>
|
| 2959 |
<button class="section-toggle">▼</button>
|
| 2960 |
</div>
|
| 2961 |
<div class="section-body">
|
|
@@ -3135,7 +3245,7 @@ Actual Pos TP FN
|
|
| 3135 |
<!-- Section 17: Decision Trees -->
|
| 3136 |
<div class="section" id="decision-trees">
|
| 3137 |
<div class="section-header">
|
| 3138 |
-
<h2>
|
| 3139 |
<button class="section-toggle">▼</button>
|
| 3140 |
</div>
|
| 3141 |
<div class="section-body">
|
|
@@ -3290,10 +3400,503 @@ Actual Pos TP FN
|
|
| 3290 |
</div>
|
| 3291 |
</div>
|
| 3292 |
|
| 3293 |
-
<!--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3294 |
<div class="section" id="ensemble-methods">
|
| 3295 |
<div class="section-header">
|
| 3296 |
-
<h2>
|
| 3297 |
<button class="section-toggle">▼</button>
|
| 3298 |
</div>
|
| 3299 |
<div class="section-body">
|
|
|
|
| 450 |
margin-right: 8px;
|
| 451 |
}
|
| 452 |
|
| 453 |
+
/* Step boxes */
|
| 454 |
+
.step {
|
| 455 |
+
background: #2a3544;
|
| 456 |
+
border-left: 4px solid #6aa9ff;
|
| 457 |
+
border-radius: 8px;
|
| 458 |
+
padding: 20px;
|
| 459 |
+
margin: 20px 0;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
.step-title {
|
| 463 |
+
font-size: 16px;
|
| 464 |
+
font-weight: 600;
|
| 465 |
+
color: #7ef0d4;
|
| 466 |
+
margin-bottom: 12px;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
.step-calculation {
|
| 470 |
+
font-family: 'Courier New', monospace;
|
| 471 |
+
font-size: 14px;
|
| 472 |
+
line-height: 1.8;
|
| 473 |
+
color: #e8eef6;
|
| 474 |
+
white-space: pre-wrap;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
/* Responsive */
|
| 478 |
@media (max-width: 1024px) {
|
| 479 |
.toc-sidebar {
|
|
|
|
| 509 |
<p class="toc-subtitle">Complete Learning Guide</p>
|
| 510 |
</div>
|
| 511 |
<nav class="toc-nav">
|
| 512 |
+
<a href="#intro" class="toc-link">📚 Introduction</a>
|
| 513 |
+
|
| 514 |
+
<div class="toc-category">
|
| 515 |
+
<div class="toc-category-header" data-category="supervised">
|
| 516 |
+
<span class="category-icon">📊</span>
|
| 517 |
+
<span class="category-title">SUPERVISED LEARNING</span>
|
| 518 |
+
<span class="category-toggle">▼</span>
|
| 519 |
+
</div>
|
| 520 |
+
<div class="toc-category-content" id="supervised-content">
|
| 521 |
+
<div class="toc-subcategory">
|
| 522 |
+
<div class="toc-subcategory-title">Regression</div>
|
| 523 |
+
<a href="#linear-regression" class="toc-link toc-sub">Linear Regression</a>
|
| 524 |
+
<a href="#gradient-descent" class="toc-link toc-sub">Gradient Descent</a>
|
| 525 |
+
</div>
|
| 526 |
+
<div class="toc-subcategory">
|
| 527 |
+
<div class="toc-subcategory-title">Classification</div>
|
| 528 |
+
<a href="#logistic-regression" class="toc-link toc-sub">Logistic Regression</a>
|
| 529 |
+
<a href="#svm" class="toc-link toc-sub">Support Vector Machines</a>
|
| 530 |
+
<a href="#knn" class="toc-link toc-sub">K-Nearest Neighbors</a>
|
| 531 |
+
<a href="#naive-bayes" class="toc-link toc-sub">Naive Bayes</a>
|
| 532 |
+
<a href="#decision-trees" class="toc-link toc-sub">Decision Trees</a>
|
| 533 |
+
<a href="#ensemble-methods" class="toc-link toc-sub">Ensemble Methods</a>
|
| 534 |
+
</div>
|
| 535 |
+
<div class="toc-subcategory">
|
| 536 |
+
<div class="toc-subcategory-title">Evaluation & Tuning</div>
|
| 537 |
+
<a href="#model-evaluation" class="toc-link toc-sub">Model Evaluation</a>
|
| 538 |
+
<a href="#cross-validation" class="toc-link toc-sub">Cross-Validation</a>
|
| 539 |
+
<a href="#optimal-k" class="toc-link toc-sub">Finding Optimal K</a>
|
| 540 |
+
<a href="#hyperparameter-tuning" class="toc-link toc-sub">Hyperparameter Tuning</a>
|
| 541 |
+
<a href="#regularization" class="toc-link toc-sub">Regularization</a>
|
| 542 |
+
<a href="#bias-variance" class="toc-link toc-sub">Bias-Variance Tradeoff</a>
|
| 543 |
+
</div>
|
| 544 |
+
</div>
|
| 545 |
+
</div>
|
| 546 |
+
|
| 547 |
+
<div class="toc-category">
|
| 548 |
+
<div class="toc-category-header" data-category="unsupervised">
|
| 549 |
+
<span class="category-icon">🔍</span>
|
| 550 |
+
<span class="category-title">UNSUPERVISED LEARNING</span>
|
| 551 |
+
<span class="category-toggle">▼</span>
|
| 552 |
+
</div>
|
| 553 |
+
<div class="toc-category-content" id="unsupervised-content">
|
| 554 |
+
<div class="toc-subcategory">
|
| 555 |
+
<div class="toc-subcategory-title">Clustering</div>
|
| 556 |
+
<a href="#kmeans" class="toc-link toc-sub">K-means Clustering</a>
|
| 557 |
+
</div>
|
| 558 |
+
<div class="toc-subcategory">
|
| 559 |
+
<div class="toc-subcategory-title">Preprocessing</div>
|
| 560 |
+
<a href="#preprocessing" class="toc-link toc-sub">Data Preprocessing</a>
|
| 561 |
+
<a href="#loss-functions" class="toc-link toc-sub">Loss Functions</a>
|
| 562 |
+
</div>
|
| 563 |
+
</div>
|
| 564 |
+
</div>
|
| 565 |
+
|
| 566 |
+
<div class="toc-category">
|
| 567 |
+
<div class="toc-category-header" data-category="reinforcement">
|
| 568 |
+
<span class="category-icon">🎮</span>
|
| 569 |
+
<span class="category-title">REINFORCEMENT LEARNING</span>
|
| 570 |
+
<span class="category-toggle">▼</span>
|
| 571 |
+
</div>
|
| 572 |
+
<div class="toc-category-content" id="reinforcement-content">
|
| 573 |
+
<a href="#rl-intro" class="toc-link toc-sub">RL Introduction</a>
|
| 574 |
+
<a href="#q-learning" class="toc-link toc-sub">Q-Learning</a>
|
| 575 |
+
<a href="#policy-gradient" class="toc-link toc-sub">Policy Gradient</a>
|
| 576 |
+
</div>
|
| 577 |
+
</div>
|
| 578 |
+
|
| 579 |
+
<a href="#algorithm-comparison" class="toc-link">📊 Algorithm Comparison</a>
|
| 580 |
</nav>
|
| 581 |
</aside>
|
| 582 |
|
| 583 |
<!-- Main Content Area -->
|
| 584 |
<main class="content-main">
|
| 585 |
<div class="content-header">
|
| 586 |
+
<h1>Machine Learning: The Ultimate Learning Platform</h1>
|
| 587 |
+
<p style="font-size: 18px; margin-bottom: 16px;">Master ML through <strong style="color: #6aa9ff;">Supervised</strong>, <strong style="color: #7ef0d4;">Unsupervised</strong> & <strong style="color: #ff8c6a;">Reinforcement Learning</strong></p>
|
| 588 |
+
<p style="font-size: 16px; color: #a9b4c2;">Complete with step-by-step mathematical solutions, interactive visualizations, and real-world examples</p>
|
| 589 |
</div>
|
| 590 |
|
| 591 |
+
<!-- ========================================
|
| 592 |
+
INTRODUCTION SECTION
|
| 593 |
+
======================================== -->
|
| 594 |
<!-- Section 1: Introduction to Machine Learning -->
|
| 595 |
<div class="section" id="intro">
|
| 596 |
<div class="section-header">
|
|
|
|
| 600 |
<div class="section-body">
|
| 601 |
<p>Machine Learning is teaching computers to learn from experience, just like humans do. Instead of programming every rule, we let the computer discover patterns in data and make decisions on its own.</p>
|
| 602 |
|
| 603 |
+
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin: 32px 0;">
|
| 604 |
+
<div style="background: rgba(106, 169, 255, 0.1); border: 2px solid #6aa9ff; border-radius: 12px; padding: 24px; text-align: center;">
|
| 605 |
+
<div style="font-size: 48px; margin-bottom: 12px;">📊</div>
|
| 606 |
+
<h4 style="color: #6aa9ff; margin-bottom: 8px;">Supervised Learning</h4>
|
| 607 |
+
<p style="font-size: 14px; color: #a9b4c2; margin: 0;">Learning with labeled data - like a teacher providing answers</p>
|
| 608 |
+
<div style="margin-top: 12px; font-size: 12px; color: #7ef0d4;">
|
| 609 |
+
<div>✓ Regression</div>
|
| 610 |
+
<div>✓ Classification</div>
|
| 611 |
+
<div>✓ Evaluation</div>
|
| 612 |
+
</div>
|
| 613 |
+
</div>
|
| 614 |
+
<div style="background: rgba(126, 240, 212, 0.1); border: 2px solid #7ef0d4; border-radius: 12px; padding: 24px; text-align: center;">
|
| 615 |
+
<div style="font-size: 48px; margin-bottom: 12px;">🔍</div>
|
| 616 |
+
<h4 style="color: #7ef0d4; margin-bottom: 8px;">Unsupervised Learning</h4>
|
| 617 |
+
<p style="font-size: 14px; color: #a9b4c2; margin: 0;">Finding patterns without labels - discovering hidden structure</p>
|
| 618 |
+
<div style="margin-top: 12px; font-size: 12px; color: #7ef0d4;">
|
| 619 |
+
<div>✓ Clustering</div>
|
| 620 |
+
<div>✓ Dimensionality Reduction</div>
|
| 621 |
+
<div>✓ Preprocessing</div>
|
| 622 |
+
</div>
|
| 623 |
+
</div>
|
| 624 |
+
<div style="background: rgba(255, 140, 106, 0.1); border: 2px solid #ff8c6a; border-radius: 12px; padding: 24px; text-align: center;">
|
| 625 |
+
<div style="font-size: 48px; margin-bottom: 12px;">🎮</div>
|
| 626 |
+
<h4 style="color: #ff8c6a; margin-bottom: 8px;">Reinforcement Learning</h4>
|
| 627 |
+
<p style="font-size: 14px; color: #a9b4c2; margin: 0;">Learning through trial & error - maximizing rewards</p>
|
| 628 |
+
<div style="margin-top: 12px; font-size: 12px; color: #7ef0d4;">
|
| 629 |
+
<div>✓ Q-Learning</div>
|
| 630 |
+
<div>✓ Policy Gradient</div>
|
| 631 |
+
<div>✓ Applications</div>
|
| 632 |
+
</div>
|
| 633 |
+
</div>
|
| 634 |
+
</div>
|
| 635 |
+
|
| 636 |
<div class="info-card">
|
| 637 |
<div class="info-card-title">Key Concepts</div>
|
| 638 |
<ul class="info-card-list">
|
|
|
|
| 681 |
<!-- Section 2: Linear Regression -->
|
| 682 |
<div class="section" id="linear-regression">
|
| 683 |
<div class="section-header">
|
| 684 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Regression</span> Linear Regression</h2>
|
| 685 |
<button class="section-toggle">▼</button>
|
| 686 |
</div>
|
| 687 |
<div class="section-body">
|
|
|
|
| 779 |
<!-- Section 3: Gradient Descent -->
|
| 780 |
<div class="section" id="gradient-descent">
|
| 781 |
<div class="section-header">
|
| 782 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Optimization</span> Gradient Descent</h2>
|
| 783 |
<button class="section-toggle">▼</button>
|
| 784 |
</div>
|
| 785 |
<div class="section-body">
|
|
|
|
| 874 |
<!-- Section 4: Logistic Regression -->
|
| 875 |
<div class="section" id="logistic-regression">
|
| 876 |
<div class="section-header">
|
| 877 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Classification</span> Logistic Regression</h2>
|
| 878 |
<button class="section-toggle">▼</button>
|
| 879 |
</div>
|
| 880 |
<div class="section-body">
|
|
|
|
| 1016 |
<!-- Section 5: Support Vector Machines (COMPREHENSIVE UPDATE) -->
|
| 1017 |
<div class="section" id="svm">
|
| 1018 |
<div class="section-header">
|
| 1019 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Classification</span> Support Vector Machines (SVM)</h2>
|
| 1020 |
<button class="section-toggle">▼</button>
|
| 1021 |
</div>
|
| 1022 |
<div class="section-body">
|
|
|
|
| 1398 |
<!-- Section 6: K-Nearest Neighbors -->
|
| 1399 |
<div class="section" id="knn">
|
| 1400 |
<div class="section-header">
|
| 1401 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Classification</span> K-Nearest Neighbors (KNN)</h2>
|
| 1402 |
<button class="section-toggle">▼</button>
|
| 1403 |
</div>
|
| 1404 |
<div class="section-body">
|
|
|
|
| 1522 |
|
| 1523 |
<div class="section" id="model-evaluation">
|
| 1524 |
<div class="section-header">
|
| 1525 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Evaluation</span> Model Evaluation</h2>
|
| 1526 |
<button class="section-toggle">▼</button>
|
| 1527 |
</div>
|
| 1528 |
<div class="section-body">
|
|
|
|
| 1975 |
|
| 1976 |
<div class="section" id="cross-validation">
|
| 1977 |
<div class="section-header">
|
| 1978 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Evaluation</span> Cross-Validation</h2>
|
| 1979 |
<button class="section-toggle">▼</button>
|
| 1980 |
</div>
|
| 1981 |
<div class="section-body">
|
|
|
|
| 2128 |
|
| 2129 |
<div class="section" id="preprocessing">
|
| 2130 |
<div class="section-header">
|
| 2131 |
+
<h2><span class="badge" style="background: rgba(126, 240, 212, 0.3); color: #7ef0d4;">🔍 Unsupervised - Preprocessing</span> Data Preprocessing</h2>
|
| 2132 |
<button class="section-toggle">▼</button>
|
| 2133 |
</div>
|
| 2134 |
<div class="section-body">
|
|
|
|
| 2666 |
<!-- Section 15: Naive Bayes (COMPREHENSIVE WITH MATH) -->
|
| 2667 |
<div class="section" id="naive-bayes">
|
| 2668 |
<div class="section-header">
|
| 2669 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised - Classification</span> Naive Bayes Classification</h2>
|
| 2670 |
<button class="section-toggle">▼</button>
|
| 2671 |
</div>
|
| 2672 |
<div class="section-body">
|
|
|
|
| 3065 |
<!-- Section 16: K-means Clustering -->
|
| 3066 |
<div class="section" id="kmeans">
|
| 3067 |
<div class="section-header">
|
| 3068 |
+
<h2><span class="badge" style="background: rgba(126, 240, 212, 0.3); color: #7ef0d4;">🔍 Unsupervised - Clustering</span> K-means Clustering</h2>
|
| 3069 |
<button class="section-toggle">▼</button>
|
| 3070 |
</div>
|
| 3071 |
<div class="section-body">
|
|
|
|
| 3245 |
<!-- Section 17: Decision Trees -->
|
| 3246 |
<div class="section" id="decision-trees">
|
| 3247 |
<div class="section-header">
|
| 3248 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised</span> Decision Trees</h2>
|
| 3249 |
<button class="section-toggle">▼</button>
|
| 3250 |
</div>
|
| 3251 |
<div class="section-body">
|
|
|
|
| 3400 |
</div>
|
| 3401 |
</div>
|
| 3402 |
|
| 3403 |
+
<!-- REINFORCEMENT LEARNING SECTIONS -->
|
| 3404 |
+
|
| 3405 |
+
<!-- Section: RL Introduction -->
|
| 3406 |
+
<div class="section" id="rl-intro">
|
| 3407 |
+
<div class="section-header">
|
| 3408 |
+
<h2><span class="badge" style="background: rgba(255, 140, 106, 0.3); color: #ff8c6a;">🎮 Reinforcement</span> Introduction to Reinforcement Learning</h2>
|
| 3409 |
+
<button class="section-toggle collapsed">▼</button>
|
| 3410 |
+
</div>
|
| 3411 |
+
<div class="section-body">
|
| 3412 |
+
<p>Reinforcement Learning (RL) is learning by trial and error, just like teaching a dog tricks! The agent takes actions in an environment, receives rewards or punishments, and learns which actions lead to the best outcomes.</p>
|
| 3413 |
+
|
| 3414 |
+
<div class="info-card">
|
| 3415 |
+
<div class="info-card-title">Key Concepts</div>
|
| 3416 |
+
<ul class="info-card-list">
|
| 3417 |
+
<li>Agent: The learner/decision maker</li>
|
| 3418 |
+
<li>Environment: The world the agent interacts with</li>
|
| 3419 |
+
<li>State: Current situation of the agent</li>
|
| 3420 |
+
<li>Action: What the agent can do</li>
|
| 3421 |
+
<li>Reward: Feedback signal (positive or negative)</li>
|
| 3422 |
+
<li>Policy: Strategy the agent follows</li>
|
| 3423 |
+
</ul>
|
| 3424 |
+
</div>
|
| 3425 |
+
|
| 3426 |
+
<h3>The RL Loop</h3>
|
| 3427 |
+
<ol>
|
| 3428 |
+
<li><strong>Observe state:</strong> Agent sees current situation</li>
|
| 3429 |
+
<li><strong>Choose action:</strong> Based on policy π(s)</li>
|
| 3430 |
+
<li><strong>Execute action:</strong> Interact with environment</li>
|
| 3431 |
+
<li><strong>Receive reward:</strong> Get feedback r</li>
|
| 3432 |
+
<li><strong>Transition to new state:</strong> Environment changes to s'</li>
|
| 3433 |
+
<li><strong>Learn and update:</strong> Improve policy</li>
|
| 3434 |
+
</ol>
|
| 3435 |
+
|
| 3436 |
+
<div class="callout info">
|
| 3437 |
+
<div class="callout-title">💡 Key Difference from Supervised Learning</div>
|
| 3438 |
+
<div class="callout-content">
|
| 3439 |
+
<strong>Supervised:</strong> "Here's the right answer for each example"<br>
|
| 3440 |
+
<strong>Reinforcement:</strong> "Try things and I'll tell you if you did well or poorly"<br>
|
| 3441 |
+
<br>
|
| 3442 |
+
RL must explore to discover good actions, while supervised learning is given correct answers upfront!
|
| 3443 |
+
</div>
|
| 3444 |
+
</div>
|
| 3445 |
+
|
| 3446 |
+
<h3>Real-World Examples</h3>
|
| 3447 |
+
<ul>
|
| 3448 |
+
<li><strong>Game Playing:</strong> AlphaGo learning to play Go by playing millions of games</li>
|
| 3449 |
+
<li><strong>Robotics:</strong> Robot learning to walk by trying different leg movements</li>
|
| 3450 |
+
<li><strong>Self-Driving Cars:</strong> Learning to drive safely through experience</li>
|
| 3451 |
+
<li><strong>Recommendation Systems:</strong> Learning what users like from their interactions</li>
|
| 3452 |
+
<li><strong>Resource Management:</strong> Optimizing data center cooling to save energy</li>
|
| 3453 |
+
</ul>
|
| 3454 |
+
|
| 3455 |
+
<h3>Exploration vs Exploitation</h3>
|
| 3456 |
+
<p>The fundamental dilemma in RL:</p>
|
| 3457 |
+
<ul>
|
| 3458 |
+
<li><strong>Exploration:</strong> Try new actions to discover better rewards</li>
|
| 3459 |
+
<li><strong>Exploitation:</strong> Use known good actions to maximize reward</li>
|
| 3460 |
+
</ul>
|
| 3461 |
+
<p>Balance is key! Too much exploration wastes time on bad actions. Too much exploitation misses better strategies.</p>
|
| 3462 |
+
|
| 3463 |
+
<div class="formula">
|
| 3464 |
+
<strong>Reward Signal:</strong>
|
| 3465 |
+
Total Return = R = r₁ + γr₂ + γ²r₃ + ... = Σ γᵗ rᵗ₊₁
|
| 3466 |
+
<br><small>where:<br>γ = discount factor (0 ≤ γ ≤ 1)<br>Future rewards are worth less than immediate rewards</small>
|
| 3467 |
+
</div>
|
| 3468 |
+
</div>
|
| 3469 |
+
</div>
|
| 3470 |
+
|
| 3471 |
+
<!-- Section: Q-Learning -->
|
| 3472 |
+
<div class="section" id="q-learning">
|
| 3473 |
+
<div class="section-header">
|
| 3474 |
+
<h2><span class="badge" style="background: rgba(255, 140, 106, 0.3); color: #ff8c6a;">🎮 Reinforcement</span> Q-Learning</h2>
|
| 3475 |
+
<button class="section-toggle collapsed">▼</button>
|
| 3476 |
+
</div>
|
| 3477 |
+
<div class="section-body">
|
| 3478 |
+
<p>Q-Learning is a value-based RL algorithm that learns the quality (Q-value) of taking each action in each state. It's model-free and can learn optimal policies even without knowing how the environment works!</p>
|
| 3479 |
+
|
| 3480 |
+
<div class="info-card">
|
| 3481 |
+
<div class="info-card-title">Key Concepts</div>
|
| 3482 |
+
<ul class="info-card-list">
|
| 3483 |
+
<li>Q-value: Expected future reward for action a in state s</li>
|
| 3484 |
+
<li>Q-table: Stores Q-values for all state-action pairs</li>
|
| 3485 |
+
<li>Off-policy: Can learn optimal policy while following exploratory policy</li>
|
| 3486 |
+
<li>Temporal Difference: Learn from each step, not just end of episode</li>
|
| 3487 |
+
</ul>
|
| 3488 |
+
</div>
|
| 3489 |
+
|
| 3490 |
+
<div class="formula">
|
| 3491 |
+
<strong>Q-Learning Update Rule:</strong>
|
| 3492 |
+
Q(s, a) ← Q(s, a) + α[r + γ · max Q(s', a') - Q(s, a)]
|
| 3493 |
+
<br><br>
|
| 3494 |
+
Breaking it down:<br>
|
| 3495 |
+
Q(s, a) = Current Q-value estimate<br>
|
| 3496 |
+
α = Learning rate (e.g., 0.1)<br>
|
| 3497 |
+
r = Immediate reward received<br>
|
| 3498 |
+
γ = Discount factor (e.g., 0.9)<br>
|
| 3499 |
+
max Q(s', a') = Best Q-value in next state<br>
|
| 3500 |
+
[r + γ · max Q(s', a') - Q(s, a)] = TD error (how wrong we were)
|
| 3501 |
+
</div>
|
| 3502 |
+
|
| 3503 |
+
<h3>Step-by-Step Example: Grid World Navigation</h3>
|
| 3504 |
+
<p><strong>Problem:</strong> Agent navigates 3x3 grid to reach goal at (2,2)</p>
|
| 3505 |
+
|
| 3506 |
+
<div class="step">
|
| 3507 |
+
<div class="step-title">STEP 1: Initialize Q-Table</div>
|
| 3508 |
+
<div class="step-calculation">
|
| 3509 |
+
States: 9 positions (0,0) to (2,2)<br>
|
| 3510 |
+
Actions: 4 directions (Up, Down, Left, Right)<br>
|
| 3511 |
+
<br>
|
| 3512 |
+
Q-table: 9 × 4 = 36 values, all initialized to 0<br>
|
| 3513 |
+
<br>
|
| 3514 |
+
Example entry: Q((1,1), Right) = 0.0
|
| 3515 |
+
</div>
|
| 3516 |
+
</div>
|
| 3517 |
+
|
| 3518 |
+
<div class="step">
|
| 3519 |
+
<div class="step-title">STEP 2: Episode 1 - Random Exploration</div>
|
| 3520 |
+
<div class="step-calculation">
|
| 3521 |
+
Start: s = (0,0)<br>
|
| 3522 |
+
<br>
|
| 3523 |
+
<strong>Step 1:</strong> Choose action a = Right (ε-greedy)<br>
|
| 3524 |
+
Execute: Move to s' = (0,1)<br>
|
| 3525 |
+
Reward: r = -1 (penalty for each step)<br>
|
| 3526 |
+
<br>
|
| 3527 |
+
Update Q((0,0), Right):<br>
|
| 3528 |
+
Q = 0 + 0.1[-1 + 0.9 × max(0, 0, 0, 0) - 0]<br>
|
| 3529 |
+
Q = 0 + 0.1[-1]<br>
|
| 3530 |
+
Q((0,0), Right) = <strong>-0.1</strong> ✓<br>
|
| 3531 |
+
<br>
|
| 3532 |
+
<strong>Step 2:</strong> s = (0,1), action = Down<br>
|
| 3533 |
+
s' = (1,1), r = -1<br>
|
| 3534 |
+
Q((0,1), Down) = 0 + 0.1[-1 + 0] = <strong>-0.1</strong><br>
|
| 3535 |
+
<br>
|
| 3536 |
+
<strong>Step 3:</strong> s = (1,1), action = Right<br>
|
| 3537 |
+
s' = (1,2), r = -1<br>
|
| 3538 |
+
Q((1,1), Right) = <strong>-0.1</strong><br>
|
| 3539 |
+
<br>
|
| 3540 |
+
<strong>Step 4:</strong> s = (1,2), action = Down<br>
|
| 3541 |
+
s' = (2,2) ← <span style="color: #7ef0d4;">GOAL!</span><br>
|
| 3542 |
+
r = +100 (big reward!)<br>
|
| 3543 |
+
<br>
|
| 3544 |
+
Q((1,2), Down) = 0 + 0.1[100 + 0]<br>
|
| 3545 |
+
Q((1,2), Down) = <strong style="color: #7ef0d4;">10.0</strong> ✓✓✓
|
| 3546 |
+
</div>
|
| 3547 |
+
</div>
|
| 3548 |
+
|
| 3549 |
+
<div class="step">
|
| 3550 |
+
<div class="step-title">STEP 3: Episode 2 - Learning Propagates Backward</div>
|
| 3551 |
+
<div class="step-calculation">
|
| 3552 |
+
Path: (0,0) → (0,1) → (1,1) → (1,2) → (2,2)<br>
|
| 3553 |
+
<br>
|
| 3554 |
+
At (1,1), choosing Right:<br>
|
| 3555 |
+
Q((1,1), Right) = -0.1 + 0.1[-1 + 0.9 × 10.0 - (-0.1)]<br>
|
| 3556 |
+
= -0.1 + 0.1[-1 + 9.0 + 0.1]<br>
|
| 3557 |
+
= -0.1 + 0.1[8.1]<br>
|
| 3558 |
+
= -0.1 + 0.81<br>
|
| 3559 |
+
Q((1,1), Right) = <strong style="color: #7ef0d4;">0.71</strong> ✓<br>
|
| 3560 |
+
<br>
|
| 3561 |
+
<span style="color: #7ef0d4;">→ The value of being near the goal propagates backward!</span>
|
| 3562 |
+
</div>
|
| 3563 |
+
</div>
|
| 3564 |
+
|
| 3565 |
+
<div class="callout success">
|
| 3566 |
+
<div class="callout-title">✅ After Many Episodes</div>
|
| 3567 |
+
<div class="callout-content">
|
| 3568 |
+
The Q-table converges to optimal values:<br>
|
| 3569 |
+
<br>
|
| 3570 |
+
Q((0,0), Right) ≈ 7.3<br>
|
| 3571 |
+
Q((1,1), Right) ≈ 8.1<br>
|
| 3572 |
+
Q((1,2), Down) ≈ 9.0<br>
|
| 3573 |
+
<br>
|
| 3574 |
+
<strong>Optimal Policy:</strong> Always move toward (2,2) via shortest path!<br>
|
| 3575 |
+
Agent has learned to navigate perfectly through trial and error.
|
| 3576 |
+
</div>
|
| 3577 |
+
</div>
|
| 3578 |
+
|
| 3579 |
+
<h3>ε-Greedy Policy</h3>
|
| 3580 |
+
<div class="formula">
|
| 3581 |
+
<strong>Action Selection:</strong><br>
|
| 3582 |
+
With probability ε: Choose random action (explore)<br>
|
| 3583 |
+
With probability 1-ε: Choose argmax Q(s,a) (exploit)<br>
|
| 3584 |
+
<br>
|
| 3585 |
+
Common: Start ε=1.0, decay to ε=0.01 over time
|
| 3586 |
+
</div>
|
| 3587 |
+
|
| 3588 |
+
<h3>Advantages</h3>
|
| 3589 |
+
<ul>
|
| 3590 |
+
<li>✓ Simple to implement</li>
|
| 3591 |
+
<li>✓ Guaranteed to converge to optimal policy</li>
|
| 3592 |
+
<li>✓ Model-free (doesn't need environment model)</li>
|
| 3593 |
+
<li>✓ Off-policy (learn from exploratory behavior)</li>
|
| 3594 |
+
</ul>
|
| 3595 |
+
|
| 3596 |
+
<h3>Disadvantages</h3>
|
| 3597 |
+
<ul>
|
| 3598 |
+
<li>✗ Doesn't scale to large/continuous state spaces</li>
|
| 3599 |
+
<li>✗ Slow convergence in complex environments</li>
|
| 3600 |
+
<li>✗ Requires discrete actions</li>
|
| 3601 |
+
</ul>
|
| 3602 |
+
</div>
|
| 3603 |
+
</div>
|
| 3604 |
+
|
| 3605 |
+
<!-- Section: Policy Gradient -->
|
| 3606 |
+
<div class="section" id="policy-gradient">
|
| 3607 |
+
<div class="section-header">
|
| 3608 |
+
<h2><span class="badge" style="background: rgba(255, 140, 106, 0.3); color: #ff8c6a;">🎮 Reinforcement</span> Policy Gradient Methods</h2>
|
| 3609 |
+
<button class="section-toggle collapsed">▼</button>
|
| 3610 |
+
</div>
|
| 3611 |
+
<div class="section-body">
|
| 3612 |
+
<p>Policy Gradient methods directly optimize the policy (action selection strategy) instead of learning value functions. They're powerful for continuous action spaces and stochastic policies!</p>
|
| 3613 |
+
|
| 3614 |
+
<div class="info-card">
|
| 3615 |
+
<div class="info-card-title">Key Concepts</div>
|
| 3616 |
+
<ul class="info-card-list">
|
| 3617 |
+
<li>Direct policy optimization: Learn πᵧ(a|s) directly</li>
|
| 3618 |
+
<li>Parameterized policy: Use neural network with weights θ</li>
|
| 3619 |
+
<li>Gradient ascent: Move parameters to maximize expected reward</li>
|
| 3620 |
+
<li>Works with continuous actions: Can output action distributions</li>
|
| 3621 |
+
</ul>
|
| 3622 |
+
</div>
|
| 3623 |
+
|
| 3624 |
+
<h3>Policy vs Value-Based Methods</h3>
|
| 3625 |
+
<table class="data-table">
|
| 3626 |
+
<thead>
|
| 3627 |
+
<tr><th>Aspect</th><th>Value-Based (Q-Learning)</th><th>Policy-Based</th></tr>
|
| 3628 |
+
</thead>
|
| 3629 |
+
<tbody>
|
| 3630 |
+
<tr><td>What it learns</td><td>Q(s,a) values</td><td>π(a|s) policy directly</td></tr>
|
| 3631 |
+
<tr><td>Action selection</td><td>argmax Q(s,a)</td><td>Sample from π(a|s)</td></tr>
|
| 3632 |
+
<tr><td>Continuous actions</td><td>Difficult</td><td>Natural</td></tr>
|
| 3633 |
+
<tr><td>Stochastic policy</td><td>Indirect</td><td>Direct</td></tr>
|
| 3634 |
+
<tr><td>Convergence</td><td>Can be unstable</td><td>Smoother</td></tr>
|
| 3635 |
+
</tbody>
|
| 3636 |
+
</table>
|
| 3637 |
+
|
| 3638 |
+
<div class="formula">
|
| 3639 |
+
<strong>Policy Gradient Theorem:</strong>
|
| 3640 |
+
∇ᵧ J(θ) = Eᵧ[∇ᵧ log πᵧ(a|s) · Qᵧ(s,a)]
|
| 3641 |
+
<br><br>
|
| 3642 |
+
Practical form (REINFORCE):<br>
|
| 3643 |
+
∇ᵧ J(θ) ≈ ∇ᵧ log πᵧ(aᵗ|sᵗ) · Gᵗ<br>
|
| 3644 |
+
<br>
|
| 3645 |
+
where:<br>
|
| 3646 |
+
Gᵗ = Total return from time t onward<br>
|
| 3647 |
+
πᵧ(a|s) = Probability of action a in state s<br>
|
| 3648 |
+
θ = Policy parameters (neural network weights)
|
| 3649 |
+
</div>
|
| 3650 |
+
|
| 3651 |
+
<h3>REINFORCE Algorithm (Monte Carlo Policy Gradient)</h3>
|
| 3652 |
+
<div class="step">
|
| 3653 |
+
<div class="step-title">Algorithm Steps</div>
|
| 3654 |
+
<div class="step-calculation">
|
| 3655 |
+
<strong>1. Initialize:</strong> Random policy parameters θ<br>
|
| 3656 |
+
<br>
|
| 3657 |
+
<strong>2. For each episode:</strong><br>
|
| 3658 |
+
a. Generate trajectory: s₀, a₀, r₁, s₁, a₁, r₂, ..., sₜ<br>
|
| 3659 |
+
b. For each time step t:<br>
|
| 3660 |
+
- Calculate return: Gᵗ = rᵗ₊₁ + γrᵗ₊₂ + γ²rᵗ₊₃ + ...<br>
|
| 3661 |
+
- Update: θ ← θ + α · Gᵗ · ∇ᵧ log πᵧ(aᵗ|sᵗ)<br>
|
| 3662 |
+
<br>
|
| 3663 |
+
<strong>3. Repeat</strong> until policy converges
|
| 3664 |
+
</div>
|
| 3665 |
+
</div>
|
| 3666 |
+
|
| 3667 |
+
<h3>Example: CartPole Balancing</h3>
|
| 3668 |
+
<p><strong>Problem:</strong> Balance a pole on a cart by moving left or right</p>
|
| 3669 |
+
|
| 3670 |
+
<div class="step">
|
| 3671 |
+
<div class="step-title">Episode Example</div>
|
| 3672 |
+
<div class="step-calculation">
|
| 3673 |
+
State: s = [cart_pos, cart_vel, pole_angle, pole_vel]<br>
|
| 3674 |
+
Actions: a ∈ {Left, Right}<br>
|
| 3675 |
+
<br>
|
| 3676 |
+
<strong>Time t=0:</strong><br>
|
| 3677 |
+
s₀ = [0.0, 0.0, 0.1, 0.0] (pole leaning right)<br>
|
| 3678 |
+
π(Left|s₀) = 0.3, π(Right|s₀) = 0.7<br>
|
| 3679 |
+
Sample action: a₀ = Right<br>
|
| 3680 |
+
Reward: r₁ = +1 (pole still balanced)<br>
|
| 3681 |
+
<br>
|
| 3682 |
+
<strong>Time t=1:</strong><br>
|
| 3683 |
+
s₁ = [0.05, 0.1, 0.08, -0.05]<br>
|
| 3684 |
+
Action: a₁ = Right<br>
|
| 3685 |
+
r₂ = +1<br>
|
| 3686 |
+
<br>
|
| 3687 |
+
... episode continues for T=200 steps ...<br>
|
| 3688 |
+
<br>
|
| 3689 |
+
<strong>Total return:</strong> G = 200 (balanced entire episode!)<br>
|
| 3690 |
+
<br>
|
| 3691 |
+
<strong>Update policy:</strong><br>
|
| 3692 |
+
For each (sᵗ, aᵗ) in trajectory:<br>
|
| 3693 |
+
θ ← θ + 0.01 × 200 × ∇ log π(aᵗ|sᵗ)<br>
|
| 3694 |
+
<br>
|
| 3695 |
+
→ Increase probability of all actions taken in this successful episode!
|
| 3696 |
+
</div>
|
| 3697 |
+
</div>
|
| 3698 |
+
|
| 3699 |
+
<div class="callout info">
|
| 3700 |
+
<div class="callout-title">💡 Why It Works</div>
|
| 3701 |
+
<div class="callout-content">
|
| 3702 |
+
<strong>Good episode (high G):</strong> Increase probability of actions taken<br>
|
| 3703 |
+
<strong>Bad episode (low G):</strong> Decrease probability of actions taken<br>
|
| 3704 |
+
<br>
|
| 3705 |
+
Over many episodes, the policy learns which actions lead to better outcomes!
|
| 3706 |
+
</div>
|
| 3707 |
+
</div>
|
| 3708 |
+
|
| 3709 |
+
<h3>Advantages</h3>
|
| 3710 |
+
<ul>
|
| 3711 |
+
<li>✓ Works with continuous action spaces</li>
|
| 3712 |
+
<li>✓ Can learn stochastic policies</li>
|
| 3713 |
+
<li>✓ Better convergence properties</li>
|
| 3714 |
+
<li>✓ Effective in high-dimensional spaces</li>
|
| 3715 |
+
</ul>
|
| 3716 |
+
|
| 3717 |
+
<h3>Disadvantages</h3>
|
| 3718 |
+
<ul>
|
| 3719 |
+
<li>✗ High variance in gradient estimates</li>
|
| 3720 |
+
<li>✗ Sample inefficient (needs many episodes)</li>
|
| 3721 |
+
<li>✗ Can get stuck in local optima</li>
|
| 3722 |
+
<li>✗ Sensitive to learning rate</li>
|
| 3723 |
+
</ul>
|
| 3724 |
+
|
| 3725 |
+
<div class="callout success">
|
| 3726 |
+
<div class="callout-title">✅ Modern Improvements</div>
|
| 3727 |
+
<div class="callout-content">
|
| 3728 |
+
<strong>Actor-Critic:</strong> Combine policy gradient with value function to reduce variance<br>
|
| 3729 |
+
<strong>PPO (Proximal Policy Optimization):</strong> Constrain policy updates for stability<br>
|
| 3730 |
+
<strong>TRPO (Trust Region):</strong> Guarantee monotonic improvement<br>
|
| 3731 |
+
<br>
|
| 3732 |
+
These advances make policy gradients practical for complex tasks like robot control and game playing!
|
| 3733 |
+
</div>
|
| 3734 |
+
</div>
|
| 3735 |
+
</div>
|
| 3736 |
+
</div>
|
| 3737 |
+
|
| 3738 |
+
<!-- Section 18: Algorithm Comparison Tool -->
|
| 3739 |
+
<div class="section" id="algorithm-comparison">
|
| 3740 |
+
<div class="section-header">
|
| 3741 |
+
<h2><span class="badge" style="background: rgba(126, 240, 212, 0.3); color: #7ef0d4;">🔄 Comparison</span> Algorithm Comparison Tool</h2>
|
| 3742 |
+
<button class="section-toggle">▼</button>
|
| 3743 |
+
</div>
|
| 3744 |
+
<div class="section-body">
|
| 3745 |
+
<p>Compare machine learning algorithms side-by-side to choose the best one for your problem!</p>
|
| 3746 |
+
|
| 3747 |
+
<!-- Step 1: Select Category -->
|
| 3748 |
+
<div class="info-card" style="background: var(--color-bg-1);">
|
| 3749 |
+
<h3 style="margin-bottom: 16px; color: var(--color-text);">Step 1: Select Learning Category</h3>
|
| 3750 |
+
<div class="radio-group">
|
| 3751 |
+
<label><input type="radio" name="category" value="all" checked> Show All</label>
|
| 3752 |
+
<label><input type="radio" name="category" value="supervised"> Supervised Learning</label>
|
| 3753 |
+
<label><input type="radio" name="category" value="unsupervised"> Unsupervised Learning</label>
|
| 3754 |
+
</div>
|
| 3755 |
+
</div>
|
| 3756 |
+
|
| 3757 |
+
<!-- Step 2: Select Algorithms -->
|
| 3758 |
+
<div class="info-card" style="background: var(--color-bg-2); margin-top: 24px;">
|
| 3759 |
+
<h3 style="margin-bottom: 16px; color: var(--color-text);">Step 2: Select Algorithms to Compare (2-5)</h3>
|
| 3760 |
+
<div id="algorithm-checkboxes" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px;">
|
| 3761 |
+
<!-- Populated by JavaScript -->
|
| 3762 |
+
</div>
|
| 3763 |
+
<p id="selection-count" style="margin-top: 12px; color: var(--color-text-secondary); font-size: 14px;">Selected: 0 algorithms</p>
|
| 3764 |
+
</div>
|
| 3765 |
+
|
| 3766 |
+
<!-- Step 3: Compare Button -->
|
| 3767 |
+
<div style="text-align: center; margin: 32px 0;">
|
| 3768 |
+
<button class="btn btn--primary" id="compare-btn" style="padding: 14px 48px; font-size: 16px;" disabled>Compare Algorithms</button>
|
| 3769 |
+
</div>
|
| 3770 |
+
|
| 3771 |
+
<!-- Comparison Results Container -->
|
| 3772 |
+
<div id="comparison-results" style="display: none;">
|
| 3773 |
+
<!-- View Selector -->
|
| 3774 |
+
<div style="display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; justify-content: center;">
|
| 3775 |
+
<button class="btn btn--secondary view-btn active" data-view="table">📊 Table View</button>
|
| 3776 |
+
<button class="btn btn--secondary view-btn" data-view="radar">🎯 Radar Chart</button>
|
| 3777 |
+
<button class="btn btn--secondary view-btn" data-view="heatmap">🔥 Heatmap</button>
|
| 3778 |
+
<button class="btn btn--secondary view-btn" data-view="decision">🌳 Decision Tree</button>
|
| 3779 |
+
<button class="btn btn--secondary view-btn" data-view="matrix">📋 Use Case Matrix</button>
|
| 3780 |
+
</div>
|
| 3781 |
+
|
| 3782 |
+
<!-- View: Table -->
|
| 3783 |
+
<div class="comparison-view" id="view-table">
|
| 3784 |
+
<h3 style="margin-bottom: 20px; text-align: center;">Side-by-Side Comparison</h3>
|
| 3785 |
+
<div style="overflow-x: auto;">
|
| 3786 |
+
<table class="data-table" id="comparison-table">
|
| 3787 |
+
<!-- Populated by JavaScript -->
|
| 3788 |
+
</table>
|
| 3789 |
+
</div>
|
| 3790 |
+
</div>
|
| 3791 |
+
|
| 3792 |
+
<!-- View: Radar Chart -->
|
| 3793 |
+
<div class="comparison-view" id="view-radar" style="display: none;">
|
| 3794 |
+
<h3 style="margin-bottom: 20px; text-align: center;">Visual Performance Comparison</h3>
|
| 3795 |
+
<p style="text-align: center; color: var(--color-text-secondary); margin-bottom: 16px;">Interactive radar chart - works in all modern browsers</p>
|
| 3796 |
+
<div class="figure">
|
| 3797 |
+
<div class="figure-placeholder" style="height: 500px;">
|
| 3798 |
+
<canvas id="radar-comparison-canvas"></canvas>
|
| 3799 |
+
</div>
|
| 3800 |
+
</div>
|
| 3801 |
+
</div>
|
| 3802 |
+
|
| 3803 |
+
<!-- View: Heatmap -->
|
| 3804 |
+
<div class="comparison-view" id="view-heatmap" style="display: none;">
|
| 3805 |
+
<!-- HTML table-based heatmap - works in ALL browsers (Chrome, Firefox, Safari, Edge, Mobile) -->
|
| 3806 |
+
<p style="text-align: center; color: var(--color-text-secondary); margin-bottom: 16px;">✓ HTML table-based visualization - 100% browser compatible</p>
|
| 3807 |
+
</div>
|
| 3808 |
+
|
| 3809 |
+
<!-- View: Decision Tree -->
|
| 3810 |
+
<div class="comparison-view" id="view-decision" style="display: none;">
|
| 3811 |
+
<h3 style="margin-bottom: 20px; text-align: center;">When to Use Which Algorithm?</h3>
|
| 3812 |
+
<div style="background: var(--color-surface); padding: 32px; border-radius: 12px; border: 1px solid var(--color-border);">
|
| 3813 |
+
<pre style="font-family: monospace; font-size: 13px; line-height: 1.8; color: var(--color-text); background: transparent; border: none; padding: 0; margin: 0; white-space: pre-wrap;">What's your use case?
|
| 3814 |
+
|
| 3815 |
+
├─ I have <strong style="color: #7ef0d4;">LABELED</strong> data
|
| 3816 |
+
│ ├─ Predict <strong style="color: #6aa9ff;">NUMBERS</strong> (Regression)
|
| 3817 |
+
│ │ ├─ Linear relationship? → <strong style="color: #7ef0d4;">Linear Regression</strong>
|
| 3818 |
+
│ │ └─ Complex patterns? → <strong style="color: #7ef0d4;">Random Forest / XGBoost</strong>
|
| 3819 |
+
│ │
|
| 3820 |
+
│ ├─ Predict <strong style="color: #6aa9ff;">CATEGORIES</strong> (Classification)
|
| 3821 |
+
│ │ ├─ Want interpretability? → <strong style="color: #7ef0d4;">Decision Trees / Naive Bayes</strong>
|
| 3822 |
+
│ │ ├─ Want best accuracy? → <strong style="color: #7ef0d4;">SVM / Random Forest</strong>
|
| 3823 |
+
│ │ ├─ Want speed? → <strong style="color: #7ef0d4;">Logistic Regression / Naive Bayes</strong>
|
| 3824 |
+
│ │ ├─ Have few samples? → <strong style="color: #7ef0d4;">Naive Bayes</strong>
|
| 3825 |
+
│ │ └─ Local patterns? → <strong style="color: #7ef0d4;">KNN</strong>
|
| 3826 |
+
│
|
| 3827 |
+
├─ I have <strong style="color: #ff8c6a;">UNLABELED</strong> data
|
| 3828 |
+
│ ├─ Want to group similar items? → <strong style="color: #7ef0d4;">K-means</strong>
|
| 3829 |
+
│ ├─ Want to reduce dimensions? → <strong style="color: #7ef0d4;">PCA</strong>
|
| 3830 |
+
│ └─ Unknown number of groups? → <strong style="color: #7ef0d4;">DBSCAN</strong>
|
| 3831 |
+
│
|
| 3832 |
+
└─ I want to <strong style="color: #ffb490;">LEARN from experience</strong>
|
| 3833 |
+
└─ Use <strong style="color: #7ef0d4;">Reinforcement Learning</strong></pre>
|
| 3834 |
+
</div>
|
| 3835 |
+
</div>
|
| 3836 |
+
|
| 3837 |
+
<!-- View: Use Case Matrix -->
|
| 3838 |
+
<div class="comparison-view" id="view-matrix" style="display: none;">
|
| 3839 |
+
<h3 style="margin-bottom: 20px; text-align: center;">Use Case Suitability Matrix</h3>
|
| 3840 |
+
<div style="overflow-x: auto;">
|
| 3841 |
+
<table class="data-table" id="matrix-table">
|
| 3842 |
+
<!-- Populated by JavaScript -->
|
| 3843 |
+
</table>
|
| 3844 |
+
</div>
|
| 3845 |
+
</div>
|
| 3846 |
+
|
| 3847 |
+
<!-- Detailed Comparison Cards -->
|
| 3848 |
+
<div id="detailed-cards" style="margin-top: 48px;">
|
| 3849 |
+
<!-- Populated by JavaScript -->
|
| 3850 |
+
</div>
|
| 3851 |
+
</div>
|
| 3852 |
+
|
| 3853 |
+
<!-- Algorithm Quiz -->
|
| 3854 |
+
<div class="info-card" style="background: var(--color-bg-5); margin-top: 48px;">
|
| 3855 |
+
<h3 style="margin-bottom: 20px; color: var(--color-text);">🎯 Not Sure Which Algorithm? Take the Quiz!</h3>
|
| 3856 |
+
<div id="quiz-container">
|
| 3857 |
+
<div class="quiz-question" id="quiz-q1">
|
| 3858 |
+
<p style="font-weight: 600; margin-bottom: 12px;">Question 1: Do you have labeled data?</p>
|
| 3859 |
+
<div class="radio-group">
|
| 3860 |
+
<label><input type="radio" name="q1" value="yes"> Yes</label>
|
| 3861 |
+
<label><input type="radio" name="q1" value="no"> No</label>
|
| 3862 |
+
</div>
|
| 3863 |
+
</div>
|
| 3864 |
+
<div class="quiz-question" id="quiz-q2" style="display: none; margin-top: 20px;">
|
| 3865 |
+
<p style="font-weight: 600; margin-bottom: 12px;">Question 2: What do you want to predict?</p>
|
| 3866 |
+
<div class="radio-group">
|
| 3867 |
+
<label><input type="radio" name="q2" value="numbers"> Numbers (Regression)</label>
|
| 3868 |
+
<label><input type="radio" name="q2" value="categories"> Categories (Classification)</label>
|
| 3869 |
+
<label><input type="radio" name="q2" value="groups"> Groups (Clustering)</label>
|
| 3870 |
+
</div>
|
| 3871 |
+
</div>
|
| 3872 |
+
<div class="quiz-question" id="quiz-q3" style="display: none; margin-top: 20px;">
|
| 3873 |
+
<p style="font-weight: 600; margin-bottom: 12px;">Question 3: How much training data do you have?</p>
|
| 3874 |
+
<div class="radio-group">
|
| 3875 |
+
<label><input type="radio" name="q3" value="little"> Very Little (<100 samples)</label>
|
| 3876 |
+
<label><input type="radio" name="q3" value="some"> Some (100-10k samples)</label>
|
| 3877 |
+
<label><input type="radio" name="q3" value="lots"> Lots (>10k samples)</label>
|
| 3878 |
+
</div>
|
| 3879 |
+
</div>
|
| 3880 |
+
<div class="quiz-question" id="quiz-q4" style="display: none; margin-top: 20px;">
|
| 3881 |
+
<p style="font-weight: 600; margin-bottom: 12px;">Question 4: Is interpretability important?</p>
|
| 3882 |
+
<div class="radio-group">
|
| 3883 |
+
<label><input type="radio" name="q4" value="very"> Very Important</label>
|
| 3884 |
+
<label><input type="radio" name="q4" value="somewhat"> Somewhat Important</label>
|
| 3885 |
+
<label><input type="radio" name="q4" value="not"> Not Important</label>
|
| 3886 |
+
</div>
|
| 3887 |
+
</div>
|
| 3888 |
+
<div id="quiz-result" style="display: none; margin-top: 24px; padding: 20px; background: var(--color-bg-3); border-radius: 8px; border-left: 4px solid var(--color-success);">
|
| 3889 |
+
<!-- Result populated by JavaScript -->
|
| 3890 |
+
</div>
|
| 3891 |
+
</div>
|
| 3892 |
+
</div>
|
| 3893 |
+
</div>
|
| 3894 |
+
</div>
|
| 3895 |
+
|
| 3896 |
+
<!-- Section 19: Ensemble Methods -->
|
| 3897 |
<div class="section" id="ensemble-methods">
|
| 3898 |
<div class="section-header">
|
| 3899 |
+
<h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">📊 Supervised</span> Ensemble Methods</h2>
|
| 3900 |
<button class="section-toggle">▼</button>
|
| 3901 |
</div>
|
| 3902 |
<div class="section-body">
|
ml_complete-all-topics/style.css
CHANGED
|
@@ -977,6 +977,103 @@ html, body {
|
|
| 977 |
color: var(--color-btn-primary-text);
|
| 978 |
}
|
| 979 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 980 |
.nav-icon {
|
| 981 |
font-size: var(--font-size-xl);
|
| 982 |
margin-right: var(--space-12);
|
|
|
|
| 977 |
color: var(--color-btn-primary-text);
|
| 978 |
}
|
| 979 |
|
| 980 |
+
/* TOC Category Styles */
|
| 981 |
+
.toc-category {
|
| 982 |
+
margin-bottom: var(--space-8);
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
.toc-category-header {
|
| 986 |
+
display: flex;
|
| 987 |
+
align-items: center;
|
| 988 |
+
padding: var(--space-12) var(--space-16);
|
| 989 |
+
background-color: rgba(var(--color-teal-500-rgb), 0.15);
|
| 990 |
+
border-radius: var(--radius-base);
|
| 991 |
+
cursor: pointer;
|
| 992 |
+
transition: all var(--duration-fast) var(--ease-standard);
|
| 993 |
+
margin-bottom: var(--space-8);
|
| 994 |
+
}
|
| 995 |
+
|
| 996 |
+
.toc-category-header:hover {
|
| 997 |
+
background-color: rgba(var(--color-teal-500-rgb), 0.25);
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
.toc-category-header[data-category="supervised"] {
|
| 1001 |
+
background-color: rgba(106, 169, 255, 0.15);
|
| 1002 |
+
}
|
| 1003 |
+
|
| 1004 |
+
.toc-category-header[data-category="supervised"]:hover {
|
| 1005 |
+
background-color: rgba(106, 169, 255, 0.25);
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
.toc-category-header[data-category="unsupervised"] {
|
| 1009 |
+
background-color: rgba(126, 240, 212, 0.15);
|
| 1010 |
+
}
|
| 1011 |
+
|
| 1012 |
+
.toc-category-header[data-category="unsupervised"]:hover {
|
| 1013 |
+
background-color: rgba(126, 240, 212, 0.25);
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
.toc-category-header[data-category="reinforcement"] {
|
| 1017 |
+
background-color: rgba(255, 140, 106, 0.15);
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
.toc-category-header[data-category="reinforcement"]:hover {
|
| 1021 |
+
background-color: rgba(255, 140, 106, 0.25);
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
.category-icon {
|
| 1025 |
+
font-size: var(--font-size-xl);
|
| 1026 |
+
margin-right: var(--space-8);
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
.category-title {
|
| 1030 |
+
flex: 1;
|
| 1031 |
+
font-size: var(--font-size-sm);
|
| 1032 |
+
font-weight: var(--font-weight-bold);
|
| 1033 |
+
color: var(--color-text);
|
| 1034 |
+
letter-spacing: 0.5px;
|
| 1035 |
+
}
|
| 1036 |
+
|
| 1037 |
+
.category-toggle {
|
| 1038 |
+
font-size: var(--font-size-sm);
|
| 1039 |
+
color: var(--color-text-secondary);
|
| 1040 |
+
transition: transform var(--duration-normal) var(--ease-standard);
|
| 1041 |
+
}
|
| 1042 |
+
|
| 1043 |
+
.category-toggle.collapsed {
|
| 1044 |
+
transform: rotate(-90deg);
|
| 1045 |
+
}
|
| 1046 |
+
|
| 1047 |
+
.toc-category-content {
|
| 1048 |
+
padding-left: var(--space-16);
|
| 1049 |
+
max-height: 1000px;
|
| 1050 |
+
overflow: hidden;
|
| 1051 |
+
transition: max-height var(--duration-normal) var(--ease-standard);
|
| 1052 |
+
}
|
| 1053 |
+
|
| 1054 |
+
.toc-category-content.collapsed {
|
| 1055 |
+
max-height: 0;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
.toc-subcategory {
|
| 1059 |
+
margin-bottom: var(--space-12);
|
| 1060 |
+
}
|
| 1061 |
+
|
| 1062 |
+
.toc-subcategory-title {
|
| 1063 |
+
font-size: var(--font-size-xs);
|
| 1064 |
+
font-weight: var(--font-weight-semibold);
|
| 1065 |
+
color: var(--color-text-secondary);
|
| 1066 |
+
text-transform: uppercase;
|
| 1067 |
+
letter-spacing: 1px;
|
| 1068 |
+
padding: var(--space-8) var(--space-8) var(--space-4) var(--space-8);
|
| 1069 |
+
}
|
| 1070 |
+
|
| 1071 |
+
.toc-link.toc-sub {
|
| 1072 |
+
padding: var(--space-8) var(--space-12);
|
| 1073 |
+
font-size: var(--font-size-sm);
|
| 1074 |
+
margin-bottom: var(--space-4);
|
| 1075 |
+
}
|
| 1076 |
+
|
| 1077 |
.nav-icon {
|
| 1078 |
font-size: var(--font-size-xl);
|
| 1079 |
margin-right: var(--space-12);
|