Using more robust statistics

We can make our code from the The time-dependent temperature mean adjusted autoregressive model section more robust by doing the following:

  • Computing the median instead of the mean
    avgs[i-1] = np.median(temp[indices])
  • Ignoring the outliers with a masked array
    temp[:cutoff] = ma.masked_array(temp[:cutoff], temp[:cutoff] < (q1 - 1.5 * irq))

We get slightly different output with the modified code, with about 70 percent of the values predicted having an absolute error of less than 2 degrees Celsius:

AR params [ 0.95095073 -0.17373633]
% delta less than 2 70.8567244325

Get Learning NumPy Array now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.