logo

파이썬 통계 | 평균() 함수

선수과목 : 통계함수개론
Python은 데이터 분석 및 통계 분야에서 매우 인기 있는 언어입니다. 운 좋게도 Python3은 평균(), 중앙값(), 모드() 등과 같은 매우 유용한 기능이 포함된 통계 모듈을 제공합니다.
평균() 함수는 주어진 숫자 목록의 평균/평균을 계산하는 데 사용할 수 있습니다. 매개변수로 전달된 데이터 세트의 평균을 반환합니다.
산술 평균은 데이터의 합을 데이터 포인트 수로 나눈 값입니다. 범위가 다양한 값 집합에서 데이터의 중심 위치를 측정한 것입니다. Python에서는 일반적으로 주어진 숫자의 합을 현재 숫자의 개수로 나누어 이를 수행합니다.

Given set of numbers : [n1, n2, n3, n5, n6] Sum of data-set = (n1 + n2 + n3 + n4 + n5) Number of data produced = 5 Average or arithmetic mean  = (n1 + n2 + n3 + n4 + n5) / 5>




자바에서 문자를 int로

통사론 : 평균([데이터 세트])
매개변수:
[데이터 세트] : 숫자 집합의 목록 또는 튜플입니다.
반품 : 제공된 데이터 세트의 샘플 산술 평균입니다.
예외 :
유형오류 숫자 값 이외의 값이 매개변수로 전달되는 경우.


코드 #1: 일하고 있는

파이썬3








# Python program to demonstrate mean()> # function from the statistics module> # Importing the statistics module> import> statistics> # list of positive integer numbers> data1>=> [>1>,>3>,>4>,>5>,>7>,>9>,>2>]> x>=> statistics.mean(data1)> # Printing the mean> print>(>'Mean is :'>, x)>

>

>

출력 :

 Mean is : 4.428571428571429>


코드 #2: 일하고 있는

파이썬3




# Python program to demonstrate mean()> # function from the statistics module> # Importing the statistics module> from> statistics>import> mean> # Importing fractions module as fr> # Enables to calculate mean of a> # set in Fraction> from> fractions>import> Fraction as fr> # tuple of positive integer numbers> data1>=> (>11>,>3>,>4>,>5>,>7>,>9>,>2>)> # tuple of a negative set of integers> data2>=> (>->1>,>->2>,>->4>,>->7>,>->12>,>->19>)> # tuple of mixed range of numbers> data3>=> (>->1>,>->13>,>->6>,>4>,>5>,>19>,>9>)> # tuple of a set of fractional numbers> data4>=> (fr(>1>,>2>), fr(>44>,>12>), fr(>10>,>3>), fr(>2>,>3>))> # dictionary of a set of values> # Only the keys are taken in> # consideration by mean()> data5>=> {>1>:>'one'>,>2>:>'two'>,>3>:>'three'>}> # Printing the mean of above datasets> print>(>'Mean of data set 1 is % s'> %> (mean(data1)))> print>(>'Mean of data set 2 is % s'> %> (mean(data2)))> print>(>'Mean of data set 3 is % s'> %> (mean(data3)))> print>(>'Mean of data set 4 is % s'> %> (mean(data4)))> print>(>'Mean of data set 5 is % s'> %> (mean(data5)))>

>

>

출력 :

Mean of data set 1 is 5.857142857142857 Mean of data set 2 is -7.5 Mean of data set 3 is 2.4285714285714284 Mean of data set 4 is 49/24 Mean of data set 5 is 2>


코드 #3: 유형오류

파이썬3




# Python3 code to demonstrate TypeError> # importing statistics module> from> statistics>import> mean> # While using dictionaries, only keys are> # taken into consideration by mean()> dic>=> {>'one'>:>1>,>'three'>:>3>,>'seven'>:>7>,> >'twenty'>:>20>,>'nine'>:>9>,>'six'>:>6>}> # Will raise TypeError> print>(mean(dic))>

>

>

출력 :

타이프스크립트로 지도
Traceback (most recent call last): File '/home/9f8a941703745a24ddce5b5f6f211e6f.py', line 29, in print(mean(dic)) File '/usr/lib/python3.5/statistics.py', line 331, in mean T, total, count = _sum(data) File '/usr/lib/python3.5/statistics.py', line 161, in _sum for n, d in map(_exact_ratio, values): File '/usr/lib/python3.5/statistics.py', line 247, in _exact_ratio raise TypeError(msg.format(type(x).__name__)) TypeError: can't convert type 'str' to numerator/denominator>


신청:
평균/산술 평균은 통계 및 큰 값을 다룰 때 매우 중요한 기능 중 하나입니다. 따라서 평균()과 같은 함수를 사용하면 대규모 데이터 세트에서 추세 및 특징 값을 추출할 수 있습니다.