deedrop1140 commited on
Commit
d79ded4
Β·
verified Β·
1 Parent(s): a62ac7b

Update templates/Random_Forest_Classifier.html

Browse files
templates/Random_Forest_Classifier.html CHANGED
@@ -5,9 +5,8 @@
5
  <head>
6
  <meta charset="UTF-8">
7
  <title>πŸ”¬ Visual Random Forest Classifier (2D)</title>
8
- <script src="https://cdn.plot.ly/plotly-2.32.0.min.js"></script>
9
-
10
- <script src="https://cdn.tailwindcss.com"></script>
11
  <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
12
  <style>
13
  /* Basic styling for info icons and tooltips */
@@ -80,26 +79,52 @@
80
  justify-content: center;
81
  }
82
 
 
 
 
 
 
 
 
 
 
 
83
  /* --- Responsive adjustments for mobile --- */
84
  /* Ensure plot containers take full width but smaller height on narrow screens */
85
  #plot, #treeComparisonPlot {
86
  width: 100%;
87
- /* default desktop height; Plotly layout height controls actual plot height */
88
  max-width: 100%;
89
  }
90
 
91
  /* On small screens make fonts and some paddings lighter so layout feels compact */
92
  @media (max-width: 640px) {
93
  body { font-size: 14px; }
94
- .text-3xl { font-size: 1.5rem; } /* smaller headline on mobile */
95
- .flow-box { padding: 1rem; min-height: 90px; }
96
- .flow-box span.text-5xl { font-size: 2rem; } /* shrink emojis */
97
- .flow-arrow { font-size: 1.8rem; margin: 0 .5rem; }
98
-
99
- /* Give plots lower heights on small screens */
100
- /* Plot height will be programmatically set via JS, but this gives a CSS fallback */
101
- #plot { height: 320px !important; }
102
- #treeComparisonPlot { height: 320px !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
  /* End responsive adjustments */
105
  </style>
@@ -146,8 +171,11 @@
146
  </button>
147
  </div>
148
 
149
- <div id="plot" class="border rounded-lg shadow-inner" style="height: 500px; width: 100%;"></div>
150
- <p id="result" class="mt-4 font-bold text-lg text-center text-gray-800"></p>
 
 
 
151
 
152
  <div class="mt-10 p-6 bg-purple-50 rounded-xl border border-purple-200">
153
  <h2 class="text-2xl font-bold mb-6 text-center text-purple-700">How Random Forest Classifies Your Data</h2>
@@ -184,18 +212,22 @@
184
  </div>
185
  </div>
186
 
187
-
188
  <p class="mt-6 text-center text-gray-600 text-sm">
189
  Random Forest combines the power of many individual decision trees to make a more robust and accurate classification, leveraging collective intelligence.
190
  </p>
191
  </div>
192
 
193
  <div class="mt-8 text-center">
194
- <a href="/liar" class="bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700">
195
- πŸ” Go to Liar Predictor
196
- </a>
197
-
198
-
 
 
 
 
 
199
 
200
  <div class="mt-8 p-6 bg-gray-50 rounded-lg border border-gray-200">
201
  <h2 class="text-2xl font-bold mb-4 text-center text-blue-700">Understanding Random Forest</h2>
@@ -381,7 +413,8 @@
381
  const w = window.innerWidth;
382
  // Choose smaller height on narrow screens
383
  const smallScreen = w <= 640;
384
- const targetHeight = smallScreen ? 320 : 500;
 
385
 
386
  // Update main plot height
387
  Plotly.relayout('plot', {height: targetHeight});
@@ -406,7 +439,6 @@
406
  // reduce marker sizes in treeComparisonPlot traces on small screens
407
  const treeMarkerSize = smallScreen ? 18 : 30;
408
  try {
409
- // forest traces start at index 1..n β€” update all scatter traces
410
  Plotly.restyle('treeComparisonPlot', {'marker.size': treeMarkerSize});
411
  } catch (e) {
412
  // ignore if restyle fails
@@ -440,9 +472,9 @@
440
  showlegend: false,
441
  xaxis: 'x1',
442
  yaxis: 'y1'
443
- };
444
 
445
- const forestTraces = [
446
  {
447
  type: "scatter",
448
  mode: "markers+lines+text",
@@ -482,9 +514,9 @@
482
  xaxis: 'x2',
483
  yaxis: 'y2'
484
  }
485
- ];
486
 
487
- const layout = {
488
  grid: { rows: 1, columns: 2, pattern: 'independent' },
489
  xaxis: {
490
  domain: [0, 0.45],
@@ -515,55 +547,45 @@
515
  text: "πŸ“Š Visualizing Decision Tree vs Random Forest",
516
  font: { size: 18 }
517
  }
518
- };
519
 
520
- Plotly.newPlot('treeComparisonPlot', [singleTreeTrace, ...forestTraces], layout, {responsive: true});
521
- // adapt its height/marker sizes immediately for current screen
522
- adaptPlotForScreen();
523
  }
524
  </script>
525
- <div class="mt-12 bg-white rounded-lg shadow-lg p-6 border border-gray-300">
526
- <h2 class="text-2xl font-bold text-center text-purple-700 mb-4">🌳 Single Tree vs Random Forest</h2>
527
- <div id="treeComparisonPlot" class="w-full" style="height: 500px;"></div>
528
- </div>
529
-
530
- <script>
531
- // (No change here β€” the tree plot creation is moved into the onload above.)
532
- </script>
533
  <!-- πŸ“š Theory Section -->
534
- <div class="mt-8 text-gray-800 space-y-4">
535
- <h3 class="text-xl font-bold text-blue-700">πŸ” Working of Random Forest Algorithm</h3>
536
- <ul class="list-disc list-inside space-y-2">
537
- <li><strong>Create Many Decision Trees:</strong> The algorithm makes many decision trees using different random parts of the data.</li>
538
- <li><strong>Pick Random Features:</strong> Each tree picks a random subset of features to make splits. This keeps trees diverse.</li>
539
- <li><strong>Each Tree Makes a Prediction:</strong> Every tree gives its own output.</li>
540
- <li><strong>Combine the Predictions:</strong>
541
- <ul class="ml-6 list-disc">
542
- <li><em>Classification:</em> Uses majority voting across trees.</li>
543
- <li><em>Regression:</em> Averages the outputs of all trees.</li>
 
 
 
 
 
 
 
 
 
 
 
544
  </ul>
545
- </li>
546
- <li><strong>Why It Works:</strong> Randomness prevents overfitting and improves overall prediction accuracy.</li>
547
- </ul>
548
-
549
- <h3 class="text-xl font-bold text-blue-700 mt-6">🌟 Key Features of Random Forest</h3>
550
- <ul class="list-disc list-inside space-y-2">
551
- <li><strong>Handles Missing Data:</strong> Works even with some missing values.</li>
552
- <li><strong>Shows Feature Importance:</strong> Identifies most important features for prediction.</li>
553
- <li><strong>Handles Complex Data:</strong> Efficient with large datasets and many features.</li>
554
- <li><strong>Versatile:</strong> Works for both classification and regression tasks.</li>
555
- </ul>
556
-
557
- <h3 class="text-xl font-bold text-blue-700 mt-6">πŸ“Œ Assumptions of Random Forest</h3>
558
- <ul class="list-disc list-inside space-y-2">
559
- <li>Each tree is independent and makes its own prediction.</li>
560
- <li>Each tree is trained on random samples and features.</li>
561
- <li>A large enough dataset is required for diverse learning.</li>
562
- <li>Combining different trees improves accuracy.</li>
563
- </ul>
564
- </div>
565
- </div>
566
 
 
 
 
 
 
 
 
 
567
  </body>
568
  </html>
569
  {% endblock %}
 
5
  <head>
6
  <meta charset="UTF-8">
7
  <title>πŸ”¬ Visual Random Forest Classifier (2D)</title>
8
+ <script src="https://cdn.plot.ly/plotly-2.32.0.min.js"></script>
9
+ <script src="https://cdn.tailwindcss.com"></script>
 
10
  <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
11
  <style>
12
  /* Basic styling for info icons and tooltips */
 
79
  justify-content: center;
80
  }
81
 
82
+ /* Plot card wrapper so we can style cards separately from content */
83
+ .plot-card {
84
+ background: white;
85
+ border: 1px solid #E5E7EB; /* gray-200 */
86
+ border-radius: 0.75rem;
87
+ padding: 1rem;
88
+ box-shadow: 0 2px 6px rgba(0,0,0,0.04);
89
+ margin-bottom: 1rem;
90
+ }
91
+
92
  /* --- Responsive adjustments for mobile --- */
93
  /* Ensure plot containers take full width but smaller height on narrow screens */
94
  #plot, #treeComparisonPlot {
95
  width: 100%;
 
96
  max-width: 100%;
97
  }
98
 
99
  /* On small screens make fonts and some paddings lighter so layout feels compact */
100
  @media (max-width: 640px) {
101
  body { font-size: 14px; }
102
+ .text-3xl { font-size: 1.25rem; } /* even smaller headline on narrow mobile */
103
+ .flow-box { padding: 0.75rem; min-height: 70px; }
104
+ .flow-box span.text-5xl { font-size: 1.6rem; } /* shrink emojis */
105
+ .flow-arrow { font-size: 1.4rem; margin: 0 .4rem; }
106
+
107
+ /* Card padding & border tighten for mobile - makes card look smaller */
108
+ .plot-card { padding: 0.5rem; border-radius: 0.5rem; margin-bottom: 0.75rem; }
109
+
110
+ /* Give plots lower heights on small screens (JS adapts too) */
111
+ #plot { height: 260px !important; }
112
+ #treeComparisonPlot { height: 260px !important; }
113
+
114
+ /* Shrink button and form input sizes */
115
+ button { padding: 0.45rem 0.75rem; font-size: 0.9rem; }
116
+ input[type="number"] { width: 4.5rem; padding: 0.35rem; font-size: 0.95rem; }
117
+
118
+ /* Reduce spacing around the main container so it feels compact */
119
+ .max-w-5xl { padding-left: 0.5rem; padding-right: 0.5rem; }
120
+ .mt-10 { margin-top: 0.75rem; }
121
+ }
122
+
123
+ /* Slight adjustments for small-tablet widths */
124
+ @media (min-width: 641px) and (max-width: 900px) {
125
+ #plot, #treeComparisonPlot { height: 380px !important; }
126
+ .plot-card { padding: 0.75rem; }
127
+ .flow-box { min-height: 90px; padding: 1rem; }
128
  }
129
  /* End responsive adjustments */
130
  </style>
 
171
  </button>
172
  </div>
173
 
174
+ <!-- Main plot card (made compact for mobile) -->
175
+ <div class="plot-card">
176
+ <div id="plot" class="border rounded-lg shadow-inner" style="height: 500px; width: 100%;"></div>
177
+ <p id="result" class="mt-4 font-bold text-lg text-center text-gray-800"></p>
178
+ </div>
179
 
180
  <div class="mt-10 p-6 bg-purple-50 rounded-xl border border-purple-200">
181
  <h2 class="text-2xl font-bold mb-6 text-center text-purple-700">How Random Forest Classifies Your Data</h2>
 
212
  </div>
213
  </div>
214
 
 
215
  <p class="mt-6 text-center text-gray-600 text-sm">
216
  Random Forest combines the power of many individual decision trees to make a more robust and accurate classification, leveraging collective intelligence.
217
  </p>
218
  </div>
219
 
220
  <div class="mt-8 text-center">
221
+ <a href="/liar" class="bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700">
222
+ πŸ” Go to Liar Predictor
223
+ </a>
224
+
225
+ <!-- Tree comparison card: also compact on mobile -->
226
+ <div class="plot-card mt-8">
227
+ <h2 class="text-2xl font-bold text-center text-purple-700 mb-4">🌳 Single Tree vs Random Forest</h2>
228
+ <div id="treeComparisonPlot" class="w-full" style="height: 500px;"></div>
229
+ </div>
230
+ </div>
231
 
232
  <div class="mt-8 p-6 bg-gray-50 rounded-lg border border-gray-200">
233
  <h2 class="text-2xl font-bold mb-4 text-center text-blue-700">Understanding Random Forest</h2>
 
413
  const w = window.innerWidth;
414
  // Choose smaller height on narrow screens
415
  const smallScreen = w <= 640;
416
+ const tabletScreen = (w > 640 && w <= 900);
417
+ const targetHeight = smallScreen ? 260 : (tabletScreen ? 380 : 500);
418
 
419
  // Update main plot height
420
  Plotly.relayout('plot', {height: targetHeight});
 
439
  // reduce marker sizes in treeComparisonPlot traces on small screens
440
  const treeMarkerSize = smallScreen ? 18 : 30;
441
  try {
 
442
  Plotly.restyle('treeComparisonPlot', {'marker.size': treeMarkerSize});
443
  } catch (e) {
444
  // ignore if restyle fails
 
472
  showlegend: false,
473
  xaxis: 'x1',
474
  yaxis: 'y1'
475
+ };
476
 
477
+ const forestTraces = [
478
  {
479
  type: "scatter",
480
  mode: "markers+lines+text",
 
514
  xaxis: 'x2',
515
  yaxis: 'y2'
516
  }
517
+ ];
518
 
519
+ const layout = {
520
  grid: { rows: 1, columns: 2, pattern: 'independent' },
521
  xaxis: {
522
  domain: [0, 0.45],
 
547
  text: "πŸ“Š Visualizing Decision Tree vs Random Forest",
548
  font: { size: 18 }
549
  }
550
+ };
551
 
552
+ Plotly.newPlot('treeComparisonPlot', [singleTreeTrace, ...forestTraces], layout, {responsive: true});
553
+ // adapt its height/marker sizes immediately for current screen
554
+ adaptPlotForScreen();
555
  }
556
  </script>
 
 
 
 
 
 
 
 
557
  <!-- πŸ“š Theory Section -->
558
+ <div class="mt-8 text-gray-800 space-y-4">
559
+ <h3 class="text-xl font-bold text-blue-700">πŸ” Working of Random Forest Algorithm</h3>
560
+ <ul class="list-disc list-inside space-y-2">
561
+ <li><strong>Create Many Decision Trees:</strong> The algorithm makes many decision trees using different random parts of the data.</li>
562
+ <li><strong>Pick Random Features:</strong> Each tree picks a random subset of features to make splits. This keeps trees diverse.</li>
563
+ <li><strong>Each Tree Makes a Prediction:</strong> Every tree gives its own output.</li>
564
+ <li><strong>Combine the Predictions:</strong>
565
+ <ul class="ml-6 list-disc">
566
+ <li><em>Classification:</em> Uses majority voting across trees.</li>
567
+ <li><em>Regression:</em> Averages the outputs of all trees.</li>
568
+ </ul>
569
+ </li>
570
+ <li><strong>Why It Works:</strong> Randomness prevents overfitting and improves overall prediction accuracy.</li>
571
+ </ul>
572
+
573
+ <h3 class="text-xl font-bold text-blue-700 mt-6">🌟 Key Features of Random Forest</h3>
574
+ <ul class="list-disc list-inside space-y-2">
575
+ <li><strong>Handles Missing Data:</strong> Works even with some missing values.</li>
576
+ <li><strong>Shows Feature Importance:</strong> Identifies most important features for prediction.</li>
577
+ <li><strong>Handles Complex Data:</strong> Efficient with large datasets and many features.</li>
578
+ <li><strong>Versatile:</strong> Works for both classification and regression tasks.</li>
579
  </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
 
581
+ <h3 class="text-xl font-bold text-blue-700 mt-6">πŸ“Œ Assumptions of Random Forest</h3>
582
+ <ul class="list-disc list-inside space-y-2">
583
+ <li>Each tree is independent and makes its own prediction.</li>
584
+ <li>Each tree is trained on random samples and features.</li>
585
+ <li>A large enough dataset is required for diverse learning.</li>
586
+ <li>Combining different trees improves accuracy.</li>
587
+ </ul>
588
+ </div>
589
  </body>
590
  </html>
591
  {% endblock %}