Time Series Analysis with Python Cookbook by Tarek A. Atwan

Time Series Analysis with Python Cookbook by Tarek A. Atwan

Author:Tarek A. Atwan
Language: eng
Format: epub
Publisher: Packt Publishing Ltd.
Published: 2022-06-10T00:00:00+00:00


How it works...

The modified z-score (robust z-score) method is very similar to the z-score approach, as it depends on defining a standard deviation threshold. What makes this method more robust to outliers is the use of the median instead of the mean. We also use the median absolute deviation (MAD) instead of the standard deviation.

There's more...

In the previous recipe, Detecting outliers using a z-score, we used kstest_normal from statsmodels to test normality.

Another helpful plot that is specifically designed to test for normality and sometimes can help detect outliers is the Quantile-Quantile plot (QQ-plot).

You can plot a QQ-plot using SciPy or statsmodels. Both will produce the same plot. The following code will show you can plot using either.

This shows how you can plot using SciPy:

import scipy

import matplotlib.pyplot as plt

res = scipy.stats.probplot(tx.values.reshape(-1), plot=plt)

This shows how you can plot using statsmodels:

from statsmodels.graphics.gofplots import qqplot

qqplot(tx.values.reshape(-1), line='s')

plt.show()

Both SciPy and statsmodels will produce the following plot:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.