- Hands-On Data Science and Python Machine Learning
- Frank Kane
- 215字
- 2021-07-15 17:15:12
Using Python to compute standard deviation and variance
Now, NumPy also makes it incredibly easy to compute the standard deviation and variance. If you want to compute the actual standard deviation of this dataset that we generated, you just call the std function right on the dataset itself. So, when NumPy creates the list, it's not just a normal Python list, it actually has some extra stuff tacked onto it so you can call functions on it, like std for standard deviation. Let's do that now:
incomes.std()
This gives us something like the following output (remember that we used random data, so your figures won't be exactly the same as mine):
20.024538249134373
When we execute that, we get a number pretty close to 20, because that's what we specified when we created our random data. We wanted a standard deviation of 20. Sure enough, 20.02, pretty close.
The variance is just a matter of calling var.
incomes.var()
This gives me the following:
400.98213209104557
It comes out to pretty close to 400, which is 202. Right, so the world makes sense! Standard deviation is just the square root of the variance, or you could say that the variance is the standard deviation squared. Sure enough, that works out, so the world works the way it should.
- 深入核心的敏捷開發:ThoughtWorks五大關鍵實踐
- NLTK基礎教程:用NLTK和Python庫構建機器學習應用
- 深入淺出Prometheus:原理、應用、源碼與拓展詳解
- Raspberry Pi Home Automation with Arduino(Second Edition)
- C語言程序設計
- 21天學通C++(第5版)
- Regression Analysis with Python
- Beginning C++ Game Programming
- Getting Started with Nano Server
- Julia數據科學應用
- 微前端設計與實現
- 透視C#核心技術:系統架構及移動端開發
- Android項目實戰:博學谷
- Python GUI設計tkinter菜鳥編程(增強版)
- Illustrator CS6中文版應用教程(第二版)