What's the `z()` function in `stats` package of Python?

2759 views python-3.x
7

In section "Using filter() to identify outliers" of Functional Python Programming - Second Edition by Steven F. Lott, page 106, there's the following code snippet:

from stats import mean, stdev, z
dist_data = list(map(dist, trip))
?_d = mean(dist_data)
?_d = stdev(dist_data)
outlier = lambda leg: z(dist(leg), ?_d, ?_d) > 3
print("Outliers", list(filter(outlier, trip)))

I googled around but found no stats package in Python. Some relevant stuff includes: statistics package since Python 3.4, and stats.zscore function in scipy. But there's no z() function in these packages.

I also searched in the source code repo of this book, and didn't find above snippet.

Where to find and install this stats package? Thanks.

answered question

Have you tried downloading code from the page at packtpub.com/books/content/support/31830?

1 Answer

12

It looks like an older function:

https://docs.scipy.org/doc/scipy-0.7.x/reference/generated/scipy.stats.z.html?highlight=z#scipy.stats.z

I am guessing you can try with the zscore function you found.

*edit: I am not saying it will work exactly the same... just that the name and implementation changed. I think you need to update your code if you want it to work... (like removing the mean and standard deviation)

posted this

Have an answer?

JD

Please login first before posting an answer.