Spaces:
Running
Running
Commit Β·
ad51ad1
1
Parent(s): 5b394bc
update ml play list
Browse filesFiles changed (2)
235 unmodified lines2362372382392402416193 unmodified lines643564366437643864396440235 unmodified linesif (section.id === 'boosting-adaboost') initBoostingAdaBoost();if (section.id === 'random-forest') initRandomForest();if (section.id === 'ensemble-methods') initEnsembleMethods();if (section.id === 'diagnostics') {// Wait for all visualizations to initializesetTimeout(showDiagnostics, 500);6193 unmodified linescontainer.innerHTML = html;}// Handle window resizelet resizeTimer;window.addEventListener('resize', () => {235 unmodified lines2362372382392402412422432442452466193 unmodified lines6440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007235 unmodified linesif (section.id === 'boosting-adaboost') initBoostingAdaBoost();if (section.id === 'random-forest') initRandomForest();if (section.id === 'ensemble-methods') initEnsembleMethods();if (section.id === 'gradient-boosting-classification') initGradientBoostingClassification();if (section.id === 'xgboost-classification') initXGBoostClassification();if (section.id === 'hierarchical-clustering') initHierarchicalClustering();if (section.id === 'dbscan') initDBSCAN();if (section.id === 'clustering-evaluation') initClusteringEvaluation();if (section.id === 'diagnostics') {// Wait for all visualizations to initializesetTimeout(showDiagnostics, 500);6193 unmodified linescontainer.innerHTML = html;}// NEW VISUALIZATIONS FOR ADDED TOPICS// Gradient Boosting Classificationfunction initGradientBoostingClassification() {const canvas1 = document.getElementById('gb-class-sequential-canvas');if (canvas1 && !canvas1.dataset.initialized) {canvas1.dataset.initialized = 'true';drawGBClassSequential();}const canvas2 = document.getElementById('gb-class-gradients-canvas');if (canvas2 && !canvas2.dataset.initialized) {canvas2.dataset.initialized = 'true';drawGBClassGradients();}}function drawGBClassSequential() {const canvas = document.getElementById('gb-class-sequential-canvas');if (!canvas) return;const iterations = [0, 1, 2, 3, 4, 5, 10];const house1 = [0.4, 0.39, 0.37, 0.35, 0.33, 0.31, 0.22];const house4 = [0.4, 0.43, 0.47, 0.52, 0.57, 0.62, 0.78];createVerifiedVisualization('gb-class-sequential-canvas', {type: 'line',data: {labels: iterations,datasets: [{label: 'House 1 (y=0): Probability β',data: house1,borderColor: '#7ef0d4',backgroundColor: 'rgba(126, 240, 212, 0.1)',borderWidth: 3,fill: true},{label: 'House 4 (y=1): Probability β',data: house4,borderColor: '#6aa9ff',backgroundColor: 'rgba(106, 169, 255, 0.1)',borderWidth: 3,fill: true}]},options: {responsive: true,maintainAspectRatio: false,plugins: {title: {display: true,text: 'Gradient Boosting Classification: Probability Updates',color: '#e8eef6',font: { size: 16 }},legend: { labels: { color: '#a9b4c2' } }},scales: {x: {title: { display: true, text: 'Iteration', color: '#a9b4c2' },grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' }},y: {title: { display: true, text: 'P(y=1)', color: '#a9b4c2' },grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' },min: 0,max: 1}}}}, 'GB Classification', 'Sequential Updates');}function drawGBClassGradients() {const canvas = document.getElementById('gb-class-gradients-canvas');if (!canvas) return;createVerifiedVisualization('gb-class-gradients-canvas', {type: 'bar',data: {labels: ['House 1', 'House 2', 'House 3', 'House 4', 'House 5'],datasets: [{label: 'Iteration 0 Gradients',data: [0.4, 0.4, 0.4, -0.6, -0.6],backgroundColor: '#ff8c6a'},{label: 'Iteration 5 Gradients',data: [0.1, 0.08, 0.09, -0.15, -0.12],backgroundColor: '#7ef0d4'}]},options: {responsive: true,maintainAspectRatio: false,plugins: {title: {display: true,text: 'Gradient Values: Shrinking Over Iterations',color: '#e8eef6',font: { size: 16 }},legend: { labels: { color: '#a9b4c2' } }},scales: {x: {grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' }},y: {title: { display: true, text: 'Gradient (p - y)', color: '#a9b4c2' },grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' }}}}}, 'GB Classification', 'Gradient Values');}// XGBoost Classificationfunction initXGBoostClassification() {const canvas = document.getElementById('xgb-class-hessian-canvas');if (canvas && !canvas.dataset.initialized) {canvas.dataset.initialized = 'true';drawXGBClassHessian();}}function drawXGBClassHessian() {const canvas = document.getElementById('xgb-class-hessian-canvas');if (!canvas) return;const houses = ['House 1', 'House 2', 'House 3', 'House 4', 'House 5'];const gradients = [0.4, 0.4, 0.4, -0.6, -0.6];const hessians = [0.24, 0.24, 0.24, 0.24, 0.24];createVerifiedVisualization('xgb-class-hessian-canvas', {type: 'bar',data: {labels: houses,datasets: [{label: 'Gradient (g)',data: gradients,backgroundColor: '#6aa9ff',yAxisID: 'y'},{label: 'Hessian (h)',data: hessians,backgroundColor: '#7ef0d4',yAxisID: 'y1'}]},options: {responsive: true,maintainAspectRatio: false,plugins: {title: {display: true,text: 'XGBoost: Gradient + Hessian Information',color: '#e8eef6',font: { size: 16 }},legend: { labels: { color: '#a9b4c2' } }},scales: {x: {grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' }},y: {type: 'linear',position: 'left',title: { display: true, text: 'Gradient', color: '#6aa9ff' },grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' }},y1: {type: 'linear',position: 'right',title: { display: true, text: 'Hessian', color: '#7ef0d4' },grid: { display: false },ticks: { color: '#a9b4c2' }}}}}, 'XGBoost Classification', 'Hessian Values');}// Hierarchical Clusteringfunction initHierarchicalClustering() {const canvas = document.getElementById('hierarchical-dendrogram-canvas');if (canvas && !canvas.dataset.initialized) {canvas.dataset.initialized = 'true';drawHierarchicalDendrogram();}}function drawHierarchicalDendrogram() {const canvas = document.getElementById('hierarchical-dendrogram-canvas');if (!canvas) {logViz('Hierarchical Clustering', 'Dendrogram', 'failed', 'Canvas not found');return;}const ctx = canvas.getContext('2d');const width = canvas.width = canvas.offsetWidth;const height = canvas.height = 450;ctx.clearRect(0, 0, width, height);ctx.fillStyle = '#1a2332';ctx.fillRect(0, 0, width, height);const padding = 60;const numPoints = 6;const pointSpacing = (width - 2 * padding) / numPoints;const labels = ['A', 'B', 'C', 'D', 'E', 'F'];// Draw points at bottomconst pointY = height - 40;labels.forEach((label, i) => {const x = padding + i * pointSpacing + pointSpacing / 2;ctx.fillStyle = '#7ef0d4';ctx.beginPath();ctx.arc(x, pointY, 6, 0, 2 * Math.PI);ctx.fill();ctx.fillStyle = '#e8eef6';ctx.font = 'bold 12px sans-serif';ctx.textAlign = 'center';ctx.fillText(label, x, pointY + 20);});// Draw dendrogram mergesconst merges = [{ points: [0, 1], height: 320 },{ points: [3, 4], height: 330 },{ points: [0, 1, 2], height: 220 },{ points: [3, 4, 5], height: 200 },{ points: [0, 1, 2, 3, 4, 5], height: 80 }];ctx.strokeStyle = '#6aa9ff';ctx.lineWidth = 2;// Merge A-Blet x1 = padding + 0 * pointSpacing + pointSpacing / 2;let x2 = padding + 1 * pointSpacing + pointSpacing / 2;ctx.beginPath();ctx.moveTo(x1, pointY);ctx.lineTo(x1, merges[0].height);ctx.lineTo(x2, merges[0].height);ctx.lineTo(x2, pointY);ctx.stroke();// Merge D-Ex1 = padding + 3 * pointSpacing + pointSpacing / 2;x2 = padding + 4 * pointSpacing + pointSpacing / 2;ctx.beginPath();ctx.moveTo(x1, pointY);ctx.lineTo(x1, merges[1].height);ctx.lineTo(x2, merges[1].height);ctx.lineTo(x2, pointY);ctx.stroke();// Merge (A-B)-Cx1 = padding + 0.5 * pointSpacing + pointSpacing / 2;x2 = padding + 2 * pointSpacing + pointSpacing / 2;ctx.beginPath();ctx.moveTo(x1, merges[0].height);ctx.lineTo(x1, merges[2].height);ctx.lineTo(x2, merges[2].height);ctx.lineTo(x2, pointY);ctx.stroke();// Merge (D-E)-Fx1 = padding + 3.5 * pointSpacing + pointSpacing / 2;x2 = padding + 5 * pointSpacing + pointSpacing / 2;ctx.beginPath();ctx.moveTo(x1, merges[1].height);ctx.lineTo(x1, merges[3].height);ctx.lineTo(x2, merges[3].height);ctx.lineTo(x2, pointY);ctx.stroke();// Final mergex1 = padding + 1.5 * pointSpacing;x2 = padding + 4.5 * pointSpacing;ctx.beginPath();ctx.moveTo(x1, merges[2].height);ctx.lineTo(x1, merges[4].height);ctx.lineTo(x2, merges[4].height);ctx.lineTo(x2, merges[3].height);ctx.stroke();// Titlectx.fillStyle = '#7ef0d4';ctx.font = 'bold 16px sans-serif';ctx.textAlign = 'center';ctx.fillText('Dendrogram: Cluster Merging History', width / 2, 30);// Y-axis labelctx.fillStyle = '#a9b4c2';ctx.font = '12px sans-serif';ctx.save();ctx.translate(20, height / 2);ctx.rotate(-Math.PI / 2);ctx.fillText('Distance', 0, 0);ctx.restore();logViz('Hierarchical Clustering', 'Dendrogram', 'success');}// DBSCANfunction initDBSCAN() {const canvas = document.getElementById('dbscan-clusters-canvas');if (canvas && !canvas.dataset.initialized) {canvas.dataset.initialized = 'true';drawDBSCANClusters();}}function drawDBSCANClusters() {const canvas = document.getElementById('dbscan-clusters-canvas');if (!canvas) {logViz('DBSCAN', 'Clusters Visualization', 'failed', 'Canvas not found');return;}const ctx = canvas.getContext('2d');const width = canvas.width = canvas.offsetWidth;const height = canvas.height = 450;ctx.clearRect(0, 0, width, height);ctx.fillStyle = '#1a2332';ctx.fillRect(0, 0, width, height);const padding = 60;const chartWidth = width - 2 * padding;const chartHeight = height - 2 * padding;const scaleX = (x) => padding + (x / 10) * chartWidth;const scaleY = (y) => height - padding - (y / 10) * chartHeight;const eps = 1.5;const epsPixels = (eps / 10) * chartWidth;// Core points (cluster 1)const core1 = [{x: 1, y: 1}, {x: 1.2, y: 1.5}, {x: 1.5, y: 1.2}];// Core points (cluster 2)const core2 = [{x: 8, y: 8}, {x: 8.2, y: 8.5}, {x: 8.5, y: 8.2}];// Border pointsconst border = [{x: 2.2, y: 2}];// Outliersconst outliers = [{x: 5, y: 5}, {x: 4.5, y: 6}];// Draw eps circles around core pointsctx.strokeStyle = 'rgba(126, 240, 212, 0.3)';ctx.lineWidth = 1;ctx.setLineDash([3, 3]);core1.forEach(p => {ctx.beginPath();ctx.arc(scaleX(p.x), scaleY(p.y), epsPixels, 0, 2 * Math.PI);ctx.stroke();});ctx.setLineDash([]);// Draw core pointscore1.forEach(p => {ctx.fillStyle = '#7ef0d4';ctx.beginPath();ctx.arc(scaleX(p.x), scaleY(p.y), 10, 0, 2 * Math.PI);ctx.fill();ctx.strokeStyle = '#1a2332';ctx.lineWidth = 2;ctx.stroke();});core2.forEach(p => {ctx.fillStyle = '#6aa9ff';ctx.beginPath();ctx.arc(scaleX(p.x), scaleY(p.y), 10, 0, 2 * Math.PI);ctx.fill();ctx.strokeStyle = '#1a2332';ctx.lineWidth = 2;ctx.stroke();});// Draw border pointsborder.forEach(p => {ctx.fillStyle = '#ffb490';ctx.beginPath();ctx.arc(scaleX(p.x), scaleY(p.y), 8, 0, 2 * Math.PI);ctx.fill();});// Draw outliersoutliers.forEach(p => {ctx.strokeStyle = '#ff8c6a';ctx.lineWidth = 3;ctx.beginPath();ctx.arc(scaleX(p.x), scaleY(p.y), 8, 0, 2 * Math.PI);ctx.stroke();});// Legendctx.fillStyle = '#7ef0d4';ctx.beginPath();ctx.arc(padding + 20, 30, 8, 0, 2 * Math.PI);ctx.fill();ctx.fillStyle = '#e8eef6';ctx.font = '12px sans-serif';ctx.textAlign = 'left';ctx.fillText('Core points', padding + 35, 35);ctx.fillStyle = '#ffb490';ctx.beginPath();ctx.arc(padding + 140, 30, 8, 0, 2 * Math.PI);ctx.fill();ctx.fillStyle = '#e8eef6';ctx.fillText('Border points', padding + 155, 35);ctx.strokeStyle = '#ff8c6a';ctx.lineWidth = 3;ctx.beginPath();ctx.arc(padding + 270, 30, 8, 0, 2 * Math.PI);ctx.stroke();ctx.fillStyle = '#e8eef6';ctx.fillText('Outliers', padding + 285, 35);// Titlectx.fillStyle = '#7ef0d4';ctx.font = 'bold 16px sans-serif';ctx.textAlign = 'center';ctx.fillText('DBSCAN: Core, Border, and Outlier Points', width / 2, height - 10);logViz('DBSCAN', 'Clusters Visualization', 'success');}// Clustering Evaluationfunction initClusteringEvaluation() {const canvas1 = document.getElementById('silhouette-plot-canvas');if (canvas1 && !canvas1.dataset.initialized) {canvas1.dataset.initialized = 'true';drawSilhouettePlot();}const canvas2 = document.getElementById('ch-index-canvas');if (canvas2 && !canvas2.dataset.initialized) {canvas2.dataset.initialized = 'true';drawCHIndex();}}function drawSilhouettePlot() {const canvas = document.getElementById('silhouette-plot-canvas');if (!canvas) return;createVerifiedVisualization('silhouette-plot-canvas', {type: 'bar',data: {labels: ['Cluster 1 Avg', 'Cluster 2 Avg', 'Cluster 3 Avg', 'Overall'],datasets: [{label: 'Silhouette Coefficient',data: [0.72, 0.68, 0.81, 0.74],backgroundColor: ['#7ef0d4', '#6aa9ff', '#ffb490', '#ff8c6a'],borderColor: ['#7ef0d4', '#6aa9ff', '#ffb490', '#ff8c6a'],borderWidth: 2}]},options: {indexAxis: 'y',responsive: true,maintainAspectRatio: false,plugins: {title: {display: true,text: 'Silhouette Coefficients: All Above 0.7 = Excellent!',color: '#e8eef6',font: { size: 16 }},legend: { display: false }},scales: {x: {title: { display: true, text: 'Silhouette Coefficient', color: '#a9b4c2' },grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' },min: 0,max: 1},y: {grid: { display: false },ticks: { color: '#a9b4c2' }}}}}, 'Clustering Evaluation', 'Silhouette Plot');}function drawCHIndex() {const canvas = document.getElementById('ch-index-canvas');if (!canvas) return;const kValues = [2, 3, 4, 5, 6, 7, 8];const chScores = [89, 234, 187, 145, 112, 95, 78];createVerifiedVisualization('ch-index-canvas', {type: 'line',data: {labels: kValues,datasets: [{label: 'Calinski-Harabasz Index',data: chScores,borderColor: '#6aa9ff',backgroundColor: 'rgba(106, 169, 255, 0.1)',borderWidth: 3,fill: true,pointRadius: kValues.map(k => k === 3 ? 10 : 6),pointBackgroundColor: kValues.map(k => k === 3 ? '#7ef0d4' : '#6aa9ff'),pointBorderWidth: kValues.map(k => k === 3 ? 3 : 2)}]},options: {responsive: true,maintainAspectRatio: false,plugins: {title: {display: true,text: 'Calinski-Harabasz Index: Optimal k = 3',color: '#e8eef6',font: { size: 16 }},legend: { labels: { color: '#a9b4c2' } }},scales: {x: {title: { display: true, text: 'Number of Clusters (k)', color: '#a9b4c2' },grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' }},y: {title: { display: true, text: 'CH Index (higher is better)', color: '#a9b4c2' },grid: { color: '#2a3544' },ticks: { color: '#a9b4c2' },min: 0}}}}, 'Clustering Evaluation', 'CH Index');}// Handle window resizelet resizeTimer;window.addEventListener('resize', () => {
532 unmodified lines53353453553653753853954019 unmodified lines5605615625635645653520 unmodified lines408640874088408940904091209 unmodified lines430143024303430443054306762 unmodified lines506950705071507250735074532 unmodified lines<a href="#decision-trees" class="toc-link toc-sub">Decision Trees (Classification)</a><a href="#bagging" class="toc-link toc-sub">Bagging</a><a href="#boosting-adaboost" class="toc-link toc-sub">Boosting (AdaBoost)</a><a href="#gradient-boosting" class="toc-link toc-sub">Gradient Boosting</a><a href="#xgboost" class="toc-link toc-sub">XGBoost</a><a href="#random-forest" class="toc-link toc-sub">Random Forest</a><a href="#ensemble-methods" class="toc-link toc-sub">Ensemble Methods Overview</a></div>19 unmodified lines<div class="toc-subcategory"><div class="toc-subcategory-title">Clustering</div><a href="#kmeans" class="toc-link toc-sub">K-means Clustering</a></div><div class="toc-subcategory"><div class="toc-subcategory-title">Preprocessing</div>3520 unmodified lines</div></div><!-- Section 19a: Gradient Boosting (NEW FROM PDF) --><div class="section" id="gradient-boosting"><div class="section-header">209 unmodified lines</div></div><!-- Section 19b: XGBoost (NEW FROM PDF) --><div class="section" id="xgboost"><div class="section-header">762 unmodified lines</div></div><!-- Section: Diagnostics --><div class="section" id="diagnostics"><div class="section-header">532 unmodified lines53353453553653753853954054154219 unmodified lines5625635645655665675685695703520 unmodified lines409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219209 unmodified lines4429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483762 unmodified lines524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458532 unmodified lines<a href="#decision-trees" class="toc-link toc-sub">Decision Trees (Classification)</a><a href="#bagging" class="toc-link toc-sub">Bagging</a><a href="#boosting-adaboost" class="toc-link toc-sub">Boosting (AdaBoost)</a><a href="#gradient-boosting" class="toc-link toc-sub">Gradient Boosting (Regression)</a><a href="#gradient-boosting-classification" class="toc-link toc-sub">Gradient Boosting (Classification)</a><a href="#xgboost" class="toc-link toc-sub">XGBoost (Regression)</a><a href="#xgboost-classification" class="toc-link toc-sub">XGBoost (Classification)</a><a href="#random-forest" class="toc-link toc-sub">Random Forest</a><a href="#ensemble-methods" class="toc-link toc-sub">Ensemble Methods Overview</a></div>19 unmodified lines<div class="toc-subcategory"><div class="toc-subcategory-title">Clustering</div><a href="#kmeans" class="toc-link toc-sub">K-means Clustering</a><a href="#hierarchical-clustering" class="toc-link toc-sub">Hierarchical Clustering</a><a href="#dbscan" class="toc-link toc-sub">DBSCAN Clustering</a><a href="#clustering-evaluation" class="toc-link toc-sub">Clustering Evaluation</a></div><div class="toc-subcategory"><div class="toc-subcategory-title">Preprocessing</div>3520 unmodified lines</div></div><!-- Section 19a-NEW: Gradient Boosting Classification --><div class="section" id="gradient-boosting-classification"><div class="section-header"><h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">π Supervised - Classification</span> Gradient Boosting Classification</h2><button class="section-toggle collapsed">βΌ</button></div><div class="section-body"><p>Gradient Boosting for classification predicts probabilities using sequential trees that minimize log loss. Each tree corrects the previous model's errors by fitting to gradients!</p><div class="info-card"><div class="info-card-title">Simple Math Breakdown</div><ul class="info-card-list"><li>Step 1: Start with log-odds F(0) = log(pos/neg)</li><li>Step 2: Calculate gradient g = p - y</li><li>Step 3: Build tree on gradients</li><li>Step 4: Update F(x) = F(0) + lr Γ tree</li><li>Step 5: Repeat to minimize errors</li></ul></div><div class="formula"><strong>Simple Explanation:</strong><br>Step 1: F(0) = log(positive_count / negative_count)<br>Step 2: g = p - y (how wrong we are)<br>Step 3: Build tree to fix errors<br>Step 4: F(x) = F(0) + learning_rate Γ tree(x)<br>Step 5: Repeat Steps 2-4 multiple times</div><h3>Real Example: House Price β₯ 170k</h3><table class="data-table"><thead><tr><th>ID</th><th>Size</th><th>Price</th><th>β₯170k?</th></tr></thead><tbody><tr><td>1</td><td>800</td><td>120k</td><td>0 (No)</td></tr><tr><td>2</td><td>900</td><td>130k</td><td>0 (No)</td></tr><tr><td>3</td><td>1000</td><td>150k</td><td>0 (No)</td></tr><tr><td>4</td><td>1100</td><td>170k</td><td>1 (Yes)</td></tr><tr><td>5</td><td>1200</td><td>200k</td><td>1 (Yes)</td></tr></tbody></table><div class="step"><div class="step-title">STEP 1: Initialize F(0)</div><div class="step-calculation">F(0) = log(positive / negative)= log(2 / 3)= <strong style="color: #7ef0d4;">-0.405</strong>Meaning: 40.5% initial chance of β₯170k</div></div><div class="step"><div class="step-title">STEP 2: Calculate Gradients</div><div class="step-calculation">For House 1:p = sigmoid(-0.405) = <strong>0.4</strong> (40% probability)y = 0 (actual)gradient g = 0.4 - 0 = <strong style="color: #ff8c6a;">0.4</strong>For House 4:p = sigmoid(-0.405) = 0.4y = 1 (actual)gradient g = 0.4 - 1 = <strong style="color: #7ef0d4;">-0.6</strong></div></div><div class="step"><div class="step-title">STEP 3: Find Best Split</div><div class="step-calculation">Test split: Size < 1050<strong>Left (Size β€ 1050):</strong> Houses 1,2,3Gradients: [0.4, 0.4, 0.4]Average = <strong>0.4</strong><strong>Right (Size > 1050):</strong> Houses 4,5Gradients: [-0.6, -0.6]Average = <strong>-0.6</strong>β This split separates positive/negative gradients!</div></div><div class="step"><div class="step-title">STEP 4: Update Predictions</div><div class="step-calculation">F1(x) = F(0) + learning_rate Γ tree(x)For House 1 (Size=800):F1(1) = -0.405 + 0.1 Γ (-0.4)= -0.405 - 0.04= <strong style="color: #7ef0d4;">-0.445</strong>New probability = sigmoid(-0.445) = <strong>0.39</strong> β Lower!</div></div><div class="figure"><div class="figure-placeholder" style="height: 400px"><canvas id="gb-class-sequential-canvas"></canvas></div><p class="figure-caption"><strong>Figure 1:</strong> Sequential prediction updates across iterations</p></div><div class="figure"><div class="figure-placeholder" style="height: 400px"><canvas id="gb-class-gradients-canvas"></canvas></div><p class="figure-caption"><strong>Figure 2:</strong> Gradient values per sample showing error correction</p></div><div class="callout success"><div class="callout-title">β Key Takeaway</div><div class="callout-content">Gradient Boosting Classification uses gradients (p - y) to sequentially build trees that correct probability predictions. Each tree reduces log loss by fitting to the errors!</div></div></div></div><!-- Section 19a: Gradient Boosting (NEW FROM PDF) --><div class="section" id="gradient-boosting"><div class="section-header">209 unmodified lines</div></div><!-- Section 19b-NEW: XGBoost Classification --><div class="section" id="xgboost-classification"><div class="section-header"><h2><span class="badge" style="background: rgba(106, 169, 255, 0.3); color: #6aa9ff;">π Supervised - Classification</span> XGBoost Classification</h2><button class="section-toggle collapsed">βΌ</button></div><div class="section-body"><p>XGBoost Classification adds Hessian (2nd derivative) and regularization to Gradient Boosting for better accuracy and less overfitting!</p><div class="info-card"><div class="info-card-title">Difference from Gradient Boosting</div><ul class="info-card-list"><li>GB: Uses gradient g = p - y</li><li>XGB: Uses gradient g AND Hessian h = p(1-p)</li><li>XGB: Adds regularization Ξ» to prevent overfitting</li><li>XGB: Better gain calculation for splits</li></ul></div><div class="formula"><strong>Hessian Formula:</strong><br>h = p Γ (1 - p)<br><br>Measures confidence of prediction:<br>β’ p = 0.5 β h = 0.25 (most uncertain)<br>β’ p = 0.9 β h = 0.09 (very confident)<br><br><strong>Gain Formula:</strong><br>Gain = GLΒ²/(HL+Ξ») + GRΒ²/(HR+Ξ») - GpΒ²/(Hp+Ξ»)</div><div class="figure"><div class="figure-placeholder" style="height: 400px"><canvas id="xgb-class-hessian-canvas"></canvas></div><p class="figure-caption"><strong>Figure:</strong> Hessian values showing prediction confidence</p></div><div class="callout success"><div class="callout-title">β Why XGBoost is Better</div><div class="callout-content">Hessian gives curvature information β better optimization path<br>Regularization Ξ» prevents overfitting β better generalization<br>Result: State-of-the-art accuracy on classification tasks!</div></div></div></div><!-- Section 19b: XGBoost (NEW FROM PDF) --><div class="section" id="xgboost"><div class="section-header">762 unmodified lines</div></div><!-- Section: Hierarchical Clustering --><div class="section" id="hierarchical-clustering"><div class="section-header"><h2><span class="badge" style="background: rgba(126, 240, 212, 0.3); color: #7ef0d4;">π Unsupervised - Clustering</span> Hierarchical Clustering</h2><button class="section-toggle collapsed">βΌ</button></div><div class="section-body"><p>Hierarchical Clustering builds a tree of clusters by repeatedly merging the closest pairs. No need to specify K upfront!</p><div class="info-card"><div class="info-card-title">Simple Steps</div><ul class="info-card-list"><li>Step 1: Start with each point as its own cluster</li><li>Step 2: Find two closest clusters</li><li>Step 3: Merge them into one cluster</li><li>Step 4: Repeat until all in one cluster</li><li>Result: Dendrogram tree showing hierarchy</li></ul></div><div class="formula"><strong>Distance Metrics:</strong><br>Euclidean: d = β((x2-x1)Β² + (y2-y1)Β²)<br>Manhattan: d = |x2-x1| + |y2-y1|<br><br><strong>Linkage Methods:</strong><br>β’ Complete: max distance between any two points<br>β’ Single: min distance between any two points<br>β’ Average: average distance between all points<br>β’ Ward: minimizes variance (BEST for most cases)</div><div class="figure"><div class="figure-placeholder" style="height: 450px"><canvas id="hierarchical-dendrogram-canvas"></canvas></div><p class="figure-caption"><strong>Figure:</strong> Dendrogram showing cluster merging history</p></div><div class="callout info"><div class="callout-title">π‘ When to Use</div><div class="callout-content">β Don't know number of clusters<br>β Want to see cluster hierarchy<br>β Small to medium datasets (<5000 points)<br>β Need interpretable results</div></div></div></div><!-- Section: DBSCAN --><div class="section" id="dbscan"><div class="section-header"><h2><span class="badge" style="background: rgba(126, 240, 212, 0.3); color: #7ef0d4;">π Unsupervised - Clustering</span> DBSCAN Clustering</h2><button class="section-toggle collapsed">βΌ</button></div><div class="section-body"><p>DBSCAN finds clusters of arbitrary shapes and automatically detects outliers! Based on density, not distance to centroids.</p><div class="info-card"><div class="info-card-title">Key Parameters</div><ul class="info-card-list"><li>eps: Neighborhood radius (e.g., 0.4)</li><li>min_samples: Minimum points in neighborhood (e.g., 3)</li><li>Core point: Has β₯ min_samples within eps</li><li>Border point: Near core point but not core itself</li><li>Outlier: Not near any core point</li></ul></div><div class="formula"><strong>Simple Algorithm:</strong><br>Step 1: Pick random unvisited point<br>Step 2: Find all points within eps radius<br>Step 3: If count β₯ min_samples β Core point!<br>Step 4: Mark all reachable points in same cluster<br>Step 5: Move to next unvisited point<br>Step 6: Points alone = Outliers β</div><div class="step"><div class="step-title">Example: eps=0.4, min_samples=3</div><div class="step-calculation"><strong>Point A at (1, 1):</strong>Points within 0.4 units: [A, B, C]Count = 3 β Core point!Start Cluster 1 with A, B, C<strong>Point D at (8, 8):</strong>Points within 0.4 units: [D, E]Count = 2 β Not coreBut near core E β Border point in Cluster 2<strong>Point G at (5, 5):</strong>No neighbors within 0.4Mark as <strong style="color: #ff8c6a;">OUTLIER</strong> β</div></div><div class="figure"><div class="figure-placeholder" style="height: 450px"><canvas id="dbscan-clusters-canvas"></canvas></div><p class="figure-caption"><strong>Figure:</strong> DBSCAN showing core, border, and outlier points</p></div><div class="callout success"><div class="callout-title">β Advantages</div><div class="callout-content">β Finds clusters of ANY shape<br>β Automatically detects outliers<br>β No need to specify number of clusters<br>β Robust to noise</div></div></div></div><!-- Section: Clustering Evaluation --><div class="section" id="clustering-evaluation"><div class="section-header"><h2><span class="badge" style="background: rgba(126, 240, 212, 0.3); color: #7ef0d4;">π Unsupervised - Evaluation</span> Clustering Evaluation Metrics</h2><button class="section-toggle collapsed">βΌ</button></div><div class="section-body"><p>How do we know if our clustering is good? Use Silhouette Coefficient and Calinski-Harabasz Index!</p><div class="info-card"><div class="info-card-title">Key Metrics</div><ul class="info-card-list"><li>Silhouette: Measures how well points fit in clusters</li><li>Range: -1 to +1 (higher is better)</li><li>Calinski-Harabasz: Between-cluster vs within-cluster variance</li><li>Range: 0 to β (higher is better)</li></ul></div><h3>Silhouette Coefficient</h3><div class="formula"><strong>For each point:</strong><br>a = average distance to points in SAME cluster<br>b = average distance to points in NEAREST cluster<br><br>Silhouette = (b - a) / max(a, b)<br><br><strong>Interpretation:</strong><br>+0.7 to +1.0: Excellent clustering<br>+0.5 to +0.7: Good clustering<br>+0.25 to +0.5: Weak clustering<br>< +0.25: Poor or no clustering</div><div class="step"><div class="step-title">Example Calculation</div><div class="step-calculation"><strong>Point A in Cluster 1:</strong>Distance to other points in Cluster 1: [0.1, 0.2]a = average = <strong>0.15</strong>Distance to nearest points in Cluster 2: [1.5, 1.8]b = average = <strong>1.65</strong>Silhouette(A) = (1.65 - 0.15) / 1.65= 1.5 / 1.65= <strong style="color: #7ef0d4;">0.909</strong> β Excellent!</div></div><h3>Calinski-Harabasz Index</h3><div class="formula"><strong>Formula:</strong><br>CH = (Between-cluster variance) / (Within-cluster variance)<br><br><strong>Interpretation:</strong><br>0-20: Poor clustering<br>20-50: Okay clustering<br>50-150: Good clustering<br>150-500: Very good clustering<br>> 500: Excellent clustering</div><div class="figure"><div class="figure-placeholder" style="height: 400px"><canvas id="silhouette-plot-canvas"></canvas></div><p class="figure-caption"><strong>Figure 1:</strong> Silhouette plot showing score per cluster</p></div><div class="figure"><div class="figure-placeholder" style="height: 400px"><canvas id="ch-index-canvas"></canvas></div><p class="figure-caption"><strong>Figure 2:</strong> Calinski-Harabasz index vs number of clusters</p></div><div class="callout info"><div class="callout-title">π‘ Choosing the Right Metric</div><div class="callout-content"><strong>Silhouette:</strong> Best for interpretability, shows per-point quality<br><strong>CH Index:</strong> Fast to compute, good for finding optimal k<br><strong>Both together:</strong> Most reliable assessment!</div></div></div></div><!-- Section: Diagnostics --><div class="section" id="diagnostics"><div class="section-header">
ml_complete-all-topics/app.js+567
ml_complete-all-topics/index.html+386-2