TeacherPuffy commited on
Commit
3e31738
·
verified ·
1 Parent(s): 934c0de

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +26 -1
index.html CHANGED
@@ -315,6 +315,28 @@
315
  ]
316
  };
317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  // Function to format the equation
319
  function formatEquation(type, coefficients) {
320
  if (type === 'Linear') {
@@ -329,7 +351,10 @@
329
 
330
  // Function to create a chart with best-fit regression
331
  function createChart(canvasId, xData, yData, xLabel, yLabel, bestFitId, bestFitAccuracyId, equationId, linearAccuracyId, expAccuracyId, quadAccuracyId) {
332
- const chartData = xData.map((x, index) => ({ x: x, y: yData[index] }));
 
 
 
333
 
334
  // Perform regressions
335
  const linear = regression.linear(chartData.map(point => [point.x, point.y]));
 
315
  ]
316
  };
317
 
318
+ // Function to remove outliers using IQR
319
+ function removeOutliers(xData, yData) {
320
+ const combinedData = xData.map((x, i) => ({ x, y: yData[i] }));
321
+
322
+ // Calculate quartiles and IQR for yData
323
+ const sortedY = yData.slice().sort((a, b) => a - b);
324
+ const Q1 = sortedY[Math.floor(sortedY.length * 0.25)];
325
+ const Q3 = sortedY[Math.floor(sortedY.length * 0.75)];
326
+ const IQR = Q3 - Q1;
327
+ const lowerBound = Q1 - 1.5 * IQR;
328
+ const upperBound = Q3 + 1.5 * IQR;
329
+
330
+ // Filter out outliers
331
+ const filteredData = combinedData.filter(point => point.y >= lowerBound && point.y <= upperBound);
332
+
333
+ // Separate x and y data
334
+ const filteredX = filteredData.map(point => point.x);
335
+ const filteredY = filteredData.map(point => point.y);
336
+
337
+ return { filteredX, filteredY };
338
+ }
339
+
340
  // Function to format the equation
341
  function formatEquation(type, coefficients) {
342
  if (type === 'Linear') {
 
351
 
352
  // Function to create a chart with best-fit regression
353
  function createChart(canvasId, xData, yData, xLabel, yLabel, bestFitId, bestFitAccuracyId, equationId, linearAccuracyId, expAccuracyId, quadAccuracyId) {
354
+ // Remove outliers
355
+ const { filteredX, filteredY } = removeOutliers(xData, yData);
356
+
357
+ const chartData = filteredX.map((x, index) => ({ x, y: filteredY[index] }));
358
 
359
  // Perform regressions
360
  const linear = regression.linear(chartData.map(point => [point.x, point.y]));