DEV Community

Adewole Oyediran
Adewole Oyediran

Posted on

🧮 Don’t Let Outliers Fool You: Introducing `robust-average` for Reliable Price Analysis

📈 The Problem

Have you ever run an average on your price list only to find the result feels… off?
That’s because the mean can lie when your data has outliers or is skewed.

In real-world data, this happens all the time:

  • A single luxury home price inflates your “average house price.”
  • A few abnormally high or low prices distort your market report.
  • Your customers get misleading information in contracts or compliance reports.

⚖️ The Solution: robust-average

robust-average is a simple but powerful Python package that does one thing really well: it intelligently selects the most robust average — mean, median, or mode — depending on your data’s shape.


🔍 How Does It Work?

1️⃣ Outlier Detection: Uses the Interquartile Range (IQR) method to flag prices that fall far outside the normal range.
2️⃣ Skewness Analysis: Measures asymmetry using scipy.stats.skew.
3️⃣ Smart Decision Rules:

  • Mean if data is clean and symmetric.
  • Median if there are outliers or strong skew.
  • Mode if a single price dominates (>50%).

You don’t need to guess which measure to use — the function returns the best option, with all the stats to back it up.


🛠️ Example Use Cases

✅ E-commerce pricing — compare prices across sellers and ignore obvious mistakes
✅ Real estate — analyze housing prices in a fair way
✅ Stock market — avoid misleading daily averages
✅ Contract negotiations — show defensible price points
✅ Regulatory reports — stay compliant with transparent methods


🚀 How to Install

pip install robust-average
Enter fullscreen mode Exit fullscreen mode

📦 Quick Example

from robust_average import robust_average

prices = [100, 105, 110, 115, 120, 500]  # That $500 is an outlier!
result = robust_average(prices)

print(result)
# Output: {'value': 112.5, 'method': 'median', ...}
Enter fullscreen mode Exit fullscreen mode

You get the selected average, method, standard deviation, skewness, and outliers — so you can explain your results to anyone.


🤝 Why It Matters

Transparent price analysis builds trust with clients, helps you make better business decisions, and keeps you legally compliant in pricing reports and contracts.


📣 Try It, Use It, Contribute!

🔗 View it on PyPI
📚 Full code and examples in the README.

Got ideas? Open an issue, fork the repo, or suggest improvements — I’d love to collaborate.


Let’s make “average” more meaningful — one price list at a time.

Top comments (0)