Outlier Impact on Scaling
Outlier Impact on Scaling
animation
analytics-ml
feature-scaling
Try Change Outlier value: from 50 to 500.
Observe Watch Min-Max distortion, Z-Score distortion, and Robust distortion after pressing Calculate.
Explain Describe how increasing the outlier from 50 changes Min-Max distortion.
Technical boundaries. The tool adds a single outlier to the selected base dataset. Distortion compares one test value's normalized value with the clean dataset.
NoteOutlier Impact on Scaling
See how a single outlier distorts Min-Max and Z-Score scaling while Robust Scaling remains stable. Drag the outlier value to see the effect in real time.
{
const baseMap = {
"Temperature (18-30 C)": [18, 20, 22, 23, 24, 25, 26, 27, 28, 30],
"Humidity (40-60 %)": [40, 42, 45, 48, 50, 52, 54, 56, 58, 60],
"Pressure (1000-1020 hPa)": [1000, 1002, 1005, 1008, 1010, 1012, 1014, 1016, 1018, 1020]
};
const base = baseMap[baseDataChoice];
const dataWithOutlier = [...base, outlierVal];
const mean = dataWithOutlier.reduce((a, b) => a + b, 0) / dataWithOutlier.length;
const std = Math.sqrt(dataWithOutlier.reduce((a, b) => a + (b - mean) ** 2, 0) / dataWithOutlier.length);
const minV = Math.min(...dataWithOutlier);
const maxV = Math.max(...dataWithOutlier);
const sorted = [...dataWithOutlier].sort((a, b) => a - b);
const n = sorted.length;
const q1 = sorted[Math.floor(n * 0.25)];
const q3 = sorted[Math.floor(n * 0.75)];
const median = sorted[Math.floor(n / 2)];
const iqr = q3 - q1;
const meanNoOut = base.reduce((a, b) => a + b, 0) / base.length;
const stdNoOut = Math.sqrt(base.reduce((a, b) => a + (b - meanNoOut) ** 2, 0) / base.length);
const minNoOut = Math.min(...base);
const maxNoOut = Math.max(...base);
const testVal = base[Math.floor(base.length / 2)];
const mmWith = maxV === minV ? 0.5 : (testVal - minV) / (maxV - minV);
const mmWithout = maxNoOut === minNoOut ? 0.5 : (testVal - minNoOut) / (maxNoOut - minNoOut);
const zsWith = std === 0 ? 0 : (testVal - mean) / std;
const zsWithout = stdNoOut === 0 ? 0 : (testVal - meanNoOut) / stdNoOut;
const robWith = iqr === 0 ? 0 : (testVal - median) / iqr;
const sortedBase = [...base].sort((a, b) => a - b);
const nB = sortedBase.length;
const medianB = sortedBase[Math.floor(nB / 2)];
const q1B = sortedBase[Math.floor(nB * 0.25)];
const q3B = sortedBase[Math.floor(nB * 0.75)];
const iqrB = q3B - q1B;
const robWithout = iqrB === 0 ? 0 : (testVal - medianB) / iqrB;
const mmDistortion = mmWithout === 0 ? 0 : Math.abs((mmWith - mmWithout) / mmWithout * 100);
const zsDistortion = zsWithout === 0 ? 0 : Math.abs((zsWith - zsWithout) / zsWithout * 100);
const robDistortion = robWithout === 0 ? 0 : Math.abs((robWith - robWithout) / robWithout * 100);
const w = 520;
const h = 140;
const barH = 24;
const maxDist = Math.max(mmDistortion, zsDistortion, robDistortion, 1);
return html`<div style="background: var(--bs-light, #f8f9fa); padding: 1.2rem; border-radius: 8px; border-left: 4px solid #9B59B6; color: var(--bs-body-color);">
<h4 style="margin-top: 0; color: #2C3E50;">Outlier Impact: Scaling test value ${testVal} with outlier = ${outlierVal}</h4>
<svg width="${w}" height="${h}" style="font-family: Arial, sans-serif; max-width: 100%;" viewBox="0 0 ${w} ${h}">
<text x="0" y="18" font-size="13" fill="#2C3E50" font-weight="bold">Min-Max distortion</text>
<rect x="180" y="5" width="${(mmDistortion / maxDist) * 300}" height="${barH}" rx="4" fill="#E74C3C" opacity="0.85"/>
<text x="${185 + (mmDistortion / maxDist) * 300}" y="22" font-size="12" fill="#2C3E50">${mmDistortion.toFixed(1)}%</text>
<text x="0" y="58" font-size="13" fill="#2C3E50" font-weight="bold">Z-Score distortion</text>
<rect x="180" y="45" width="${(zsDistortion / maxDist) * 300}" height="${barH}" rx="4" fill="#E67E22" opacity="0.85"/>
<text x="${185 + (zsDistortion / maxDist) * 300}" y="62" font-size="12" fill="#2C3E50">${zsDistortion.toFixed(1)}%</text>
<text x="0" y="98" font-size="13" fill="#2C3E50" font-weight="bold">Robust distortion</text>
<rect x="180" y="85" width="${(robDistortion / maxDist) * 300}" height="${barH}" rx="4" fill="#16A085" opacity="0.85"/>
<text x="${185 + (robDistortion / maxDist) * 300}" y="102" font-size="12" fill="#2C3E50">${robDistortion.toFixed(1)}%</text>
<text x="0" y="${h - 5}" font-size="11" fill="#7F8C8D">Distortion = % change in normalized value vs. clean dataset</text>
</svg>
<p style="margin-top: 0.6rem; margin-bottom: 0; font-size: 0.9em; color: #7F8C8D;">
${outlierVal > base[base.length - 1] * 1.5
? "The outlier is far from the data range. Notice how Robust Scaling barely changes while Min-Max is severely compressed."
: "Try increasing the outlier value further to see dramatic differences between scaling methods."}
</p>
</div>`;
}