Compute three measures of a nonempty one-dimensional numeric dataset. The mean is:
xˉ=n1i=1∑nxiThe median is the middle sorted value, or the average of the two middle values when n is even. The mode is the most frequent value. If several values share the highest frequency, choose the smallest. Return mean, median, and mode in a dictionary of Python floats.
Input: x = [1, 2, 3, 4, 5]
Output: {"mean": 3.0, "median": 3.0, "mode": 1.0}
Explanation: Every value appears once, so the smallest value wins the mode tie.
Input: x = [1, 2, 2, 3, 4]
Output: {"mean": 2.4, "median": 2.0, "mode": 2.0}
Input: x = [1, 2, 3, 4]
Output: {"mean": 2.5, "median": 2.5, "mode": 1.0}
Use np.mean and np.median for the first two values.
Count values with Counter, find the highest frequency, then take the smallest matching key.
Sign in to take notes on this problem
Accepts: array
Compute three measures of a nonempty one-dimensional numeric dataset. The mean is:
xˉ=n1i=1∑nxiThe median is the middle sorted value, or the average of the two middle values when n is even. The mode is the most frequent value. If several values share the highest frequency, choose the smallest. Return mean, median, and mode in a dictionary of Python floats.
Input: x = [1, 2, 3, 4, 5]
Output: {"mean": 3.0, "median": 3.0, "mode": 1.0}
Explanation: Every value appears once, so the smallest value wins the mode tie.
Input: x = [1, 2, 2, 3, 4]
Output: {"mean": 2.4, "median": 2.0, "mode": 2.0}
Input: x = [1, 2, 3, 4]
Output: {"mean": 2.5, "median": 2.5, "mode": 1.0}
Use np.mean and np.median for the first two values.
Count values with Counter, find the highest frequency, then take the smallest matching key.
Sign in to take notes on this problem
Accepts: array