From the course: Machine Learning Foundations: Statistics
The mode - Python Tutorial
From the course: Machine Learning Foundations: Statistics
The mode
- [Instructor] There is one more basic summary statistic called the mode. In our previous company's salary story, we could easily find the mode. The mode is the value or values that appear most often in data. In our case, it's 90,000, as 10 out of 25 employees have a yearly salary of $90,000. A dataset can have one or more modes. The mode is a different measure from the mean, which is the average of the numbers in a set. It's also different from median, which is the midpoint of a set. When we find the mode in the dataset, we know which data points occur most commonly. But why would we want to calculate the mode if we have the mean and the median? It is not affected by extreme values. It is easy to identify in a dataset and in discrete frequency distribution. It is very useful for qualitative data. So how do we calculate the mode? Calculating the mode is easy and straightforward. We have to sort the data points from lowest to highest or even highest to lowest, and then count how many times each data point appears in the set. The one that appears the most is the mode. Now let's head on to Jupyter Notebook and learn how to calculate the mean, the median, and the mode. I have already prepared everything. So we will run our code cell by cell by using Shift + Enter. Calculating these three most popular statistics measures is simple using NumPy and SimPy libraries. So we have already imported them, and we are going to use our famous salaries example. Third dataset is salaries. So to calculate the mean, we just have to call the mean function from the NumPy library. Similarly, to calculate the median, we have to call the median function from the same library. For the mode, NumPy likes the mode function, so we are going to code the mode function from the SimPy library. As simple as that, we get our values.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.