- Hands-On Data Science and Python Machine Learning
- Frank Kane
- 128字
- 2021-07-15 17:15:09
Calculating median using the NumPy package
Alright, so computing the median is just as simple as computing the mean. Just like we had NumPy mean, we have a NumPy median function as well.
We can just use the median function on incomes, which is our list of data, and that will give us the median. In this case, that came up to $26,911, which isn't very different from the mean of $26988. Again, the initial data was random, so your values will be slightly different.
np.median(incomes)
The following is the output of the preceding code:
Out[4]: 26911.948365056276
We don't expect to see a lot of outliers because this is a nice normal distribution. Median and mean will be comparable when you don't have a lot of weird outliers.
推薦閱讀
- Python快樂編程:人工智能深度學習基礎
- OpenDaylight Cookbook
- Python機器學習:數據分析與評分卡建模(微課版)
- C#編程入門指南(上下冊)
- ASP.NET Core Essentials
- Java Web及其框架技術
- Groovy for Domain:specific Languages(Second Edition)
- 利用Python進行數據分析
- Mastering Business Intelligence with MicroStrategy
- Solr Cookbook(Third Edition)
- 計算機應用基礎教程(Windows 7+Office 2010)
- 動手打造深度學習框架
- Mastering Concurrency Programming with Java 9(Second Edition)
- Hands-On Robotics Programming with C++
- 從零開始學Selenium自動化測試:基于Python:視頻教學版