程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python notes - meaning and operation of confidence interval

編輯:Python

Basic concepts

Here we need to know a few concepts !

mean value ( Average ): The average of a set of data , For example, my favorite average score in my student days ;

variance : The degree to which a set of data deviates from the average ;

Standard deviation ( Standard error ): Variance open root sign , Reflect the dispersion of data ;

confidence interval : Statistical data error range , So there is an upper and lower value , For example, it is written on agricultural products 5kg±5%.

Confidence level : Credible probability , For example, the confidence level is 95%, Such as 100 Data , Yes 95 Data is on the above confidence interval .

Calculate the confidence interval

① Calculating mean ;

② Find standard error ;

③ Look up the table z value , The following table :

Confidence level |z| value 90%1.6495%1.9699%2.58

④ Calculate the confidence interval :

a = Sample mean - |z| * Standard deviation

b = Sample mean +|z| * Standard deviation

Python example

The following code :

import numpy as np
from scipy import stats
valueList = [95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 200]
if __name__ == '__main__':
averageValue = np.mean(valueList)
print(" The sample mean is :", averageValue)
standardError = stats.sem(valueList)
print(" The sample standard error is :", standardError)
a = averageValue - 1.96 * standardError
b = averageValue + 1.96 * standardError
print(" Interval estimate :[", a, "," ,b, "]")
pass

The running screenshot is as follows :

  Available information :

① The average value of the sample is 108.33;

② The dispersion degree of the sample is 8.38;

③ The confidence level here is 95%, Corresponding |z| The value is 1.96;

④ Yes 95% Probability , The overall sample will fall to 91.90~124.76 In this range .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved