1. 程式人生 > >[第15課] 統計:標準差

[第15課] 統計:標準差

– Start

標準差 (standard deviation)

標準差σ是表述資料和均值之間的偏離程度的另一個重要標誌。它等於方差的平方根。

標準差公式: σ=σ2σ=\sqrt{σ^2} 樣本標準差公式: S=S2S=\sqrt{S^2}

Python

import numpy as np

# 定義資料集
data_set = np.array([1, 2, 3, 8, 7])
print(f'data_set={data_set}')

# 均值
mean = np.mean(data_set)
print(f'mean of data_set = {mean}')

# 方差 & 標準差
variance = np.var(data_set)
standard_deviation = np.std(data_set)
print(f'variance of data_set = {variance}')
print(f'standard deviation of data_set = {standard_deviation}')


# 樣本方差 & 樣本標準差
variance = np.var(data_set, ddof=1)
sample_standard_deviation = np.std(data_set, ddof=1)
print(f'variance of data_set = {variance}')
print(f'sample standard deviation of data_set = {sample_standard_deviation}')

– 更多參見: – 聲 明:轉載請註明出處 – Last Updated on 2018-10-27 – Written by ShangBo on 2018-10-27 – End