Python 통계 모듈의 stdev() 메서드
Python의 통계 모듈은 다음과 같은 기능을 제공합니다. 표준편차() , 표준편차를 계산하는 데 사용할 수 있습니다. stdev() 함수는 전체 모집단이 아닌 데이터 샘플의 표준 편차만 계산합니다.
전체 모집단의 표준 편차를 계산하려면 다음과 같은 또 다른 함수를 사용하세요. pstdev() 사용.
표준 편차 통계의 확산 정도를 측정하는 것입니다. 이는 데이터 값 집합의 확산 측정, 변형을 정량화하는 데 사용됩니다. 이는 분산과 매우 유사하며 편차의 척도를 제공하는 반면 분산은 제곱 값을 제공합니다.
표준 편차 측정값이 낮으면 데이터가 덜 분산되어 있음을 나타내고, 표준 편차 값이 높으면 세트의 데이터가 평균 평균 값과 다르게 분산되어 있음을 나타냅니다. 표준편차의 유용한 특성은 분산과 달리 데이터와 동일한 단위로 표현된다는 것입니다.
Standard Deviation is calculated by : where x1, x2, x3.....xn are observed values in sample data, is the mean value of observations andN is the number of sample observations.
구문: stdev( [데이터 세트], xbar )
매개변수:
[데이터] : 실수 값이 있는 반복 가능 항목입니다.
엑스바 (선택 과목) : 데이터 세트의 실제 평균을 값으로 사용합니다.
반환 유형: 매개변수로 전달된 값의 실제 표준편차를 반환합니다.
예외:
통계오류 매개변수로 전달된 값이 2개 미만인 데이터 세트에 대해 발생합니다.
불가능하거나 정밀도가 낮은 값 값이 다음과 같이 제공되는 경우 엑스바 데이터 세트의 실제 평균과 일치하지 않습니다.
코드 #1:
파이썬3
# Python code to demonstrate stdev() function> # importing Statistics module> import> statistics> # creating a simple data - set> sample> => [> 1> ,> 2> ,> 3> ,> 4> ,> 5> ]> # Prints standard deviation> # xbar is set to default value of 1> print> (> 'Standard Deviation of sample is % s '> > %> (statistics.stdev(sample)))> |
출력 :
Standard Deviation of the sample is 1.5811388300841898
코드 #2: 다양한 데이터 유형 세트에 대한 stdev() 시연
파이썬3
# Python code to demonstrate stdev()> # function on various range of datasets> # importing the statistics module> from> statistics> import> stdev> # importing fractions as parameter values> from> fractions> import> Fraction as fr> # creating a varying range of sample sets> # numbers are spread apart but not very much> sample1> => (> 1> ,> 2> ,> 5> ,> 4> ,> 8> ,> 9> ,> 12> )> # tuple of a set of negative integers> sample2> => (> -> 2> ,> -> 4> ,> -> 3> ,> -> 1> ,> -> 5> ,> -> 6> )> # tuple of a set of positive and negative numbers> # data-points are spread apart considerably> sample3> => (> -> 9> ,> -> 1> ,> -> 0> ,> 2> ,> 1> ,> 3> ,> 4> ,> 19> )> # tuple of a set of floating point values> sample4> => (> 1.23> ,> 1.45> ,> 2.1> ,> 2.2> ,> 1.9> )> # Print the standard deviation of> # following sample sets of observations> print> (> 'The Standard Deviation of Sample1 is % s'> > %> (stdev(sample1)))> > print> (> 'The Standard Deviation of Sample2 is % s'> > %> (stdev(sample2)))> > print> (> 'The Standard Deviation of Sample3 is % s'> > %> (stdev(sample3)))> > > print> (> 'The Standard Deviation of Sample4 is % s'> > %> (stdev(sample4)))> |
출력 :
The Standard Deviation of Sample1 is 3.9761191895520196 The Standard Deviation of Sample2 is 1.8708286933869707 The Standard Deviation of Sample3 is 7.8182478855559445 The Standard Deviation of Sample4 is 0.41967844833872525
코드 #3: variance()와 stdev() 결과의 차이점을 보여줍니다.
파이썬3
# Python code to demonstrate difference> # in results of stdev() and variance()> # importing Statistics module> import> statistics> # creating a simple data-set> sample> => [> 1> ,> 2> ,> 3> ,> 4> ,> 5> ]> # Printing standard deviation> # xbar is set to default value of 1> print> (> 'Standard Deviation of the sample is % s '> > %> (statistics.stdev(sample)))> # variance is approximately the> # squared result of what stdev is> print> (> 'Variance of the sample is % s'> > %> (statistics.variance(sample)))> |
출력 :
Standard Deviation of the sample is 1.5811388300841898 Variance of the sample is 2.5
코드 #4: 의 사용을 시연 엑스바 매개변수
파이썬3
# Python code to demonstrate use of xbar> # parameter while using stdev() function> # Importing statistics module> import> statistics> # creating a sample list> sample> => (> 1> ,> 1.3> ,> 1.2> ,> 1.9> ,> 2.5> ,> 2.2> )> # calculating the mean of sample set> m> => statistics.mean(sample)> # xbar is nothing but stores> # the mean of the sample set> # calculating the variance of sample set> print> (> 'Standard Deviation of Sample set is % s'> > %> (statistics.stdev(sample, xbar> => m)))> |
출력 :
Standard Deviation of Sample set is 0.6047037842337906
코드 #5: 통계 오류를 보여줍니다.
파이썬3
# Python code to demonstrate StatisticsError> # importing the statistics module> import> statistics> # creating a data-set with one element> sample> => [> 1> ]> # will raise StatisticsError> print> (statistics.stdev(sample))> |
출력 :
Traceback (most recent call last): File '/home/f921f9269b061f1cc4e5fc74abf6ce10.py', line 12, in print(statistics.stdev(sample)) File '/usr/lib/python3.5/statistics.py', line 617, in stdev var = variance(data, xbar) File '/usr/lib/python3.5/statistics.py', line 555, in variance raise StatisticsError('variance requires at least two data points') statistics.StatisticsError: variance requires at least two data points 신청:
- 표준편차는 통계수학과 통계 연구 분야에서 매우 중요합니다. 일반적으로 통계 계산의 신뢰도를 측정하는 데 사용됩니다. 예를 들어, 시험 점수 계산의 오차 범위는 동일한 시험을 여러 번 실시할 경우 결과의 예상 표준 편차를 계산하여 결정됩니다.
- 이는 금융 연구 분야에서 매우 유용할 뿐만 아니라 손익 마진을 결정하는 데도 도움이 됩니다. 표준편차도 중요합니다. 여기서 투자수익률의 표준편차는 투자의 변동성을 측정하는 것입니다.