scipy之t分布獲取均值置信區(qū)間

import json
import math
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

data_list = []
with open('test_130380_73.log','r') as f:
    data = f.readlines()
    #readlines按行讀取返回?cái)?shù)組,遍歷數(shù)組元素
    for i in data:
        item = i.split('<<<<<')
        each = item[1].split('>')
        data_list.append(json.loads(each[0]) )

cache = []
mysql = []
emqt = []
push = []
all = []
for dic in data_list:
    if dic['type'] == 'mysql':
        mysql.append(dic['use'])
    elif dic['type'] == 'cache':
        cache.append(dic['use'])
    elif dic['type'] == 'emqt':
        emqt.append(dic['use'])
    elif dic['type'] == 'push':
        push.append(dic['use'])
    elif dic['type'] == 'all':
        all.append(dic['use'])

# print('cache用時(shí):',cache)
# print('mysql時(shí)間:',mysql)
# print('emqt時(shí)間:',emqt)
# print('push時(shí)間:',push)
# print('all時(shí)間:',all)

#stats.t.interval(置信度,自由度,均值,標(biāo)準(zhǔn)差)   得到置信區(qū)間
mysql_ci = stats.t.interval(0.95, df=len(mysql)-1, loc=np.mean(mysql), scale=stats.sem(mysql))
cache_ci = stats.t.interval(0.95, df=len(cache)-1, loc=np.mean(cache), scale=stats.sem(cache))
emqt_ci = stats.t.interval(0.95, df=len(emqt)-1, loc=np.mean(emqt), scale=stats.sem(emqt))
push_ci = stats.t.interval(0.95, df=len(push)-1, loc=np.mean(push), scale=stats.sem(push))
all_ci = stats.t.interval(0.95, df=len(all)-1, loc=np.mean(all), scale=stats.sem(all))

print('mysql_ci',mysql_ci)
print('cache_ci',cache_ci)
print('emqt_ci',emqt_ci)
print('push_ci',push_ci)
print('all_ci',all_ci)
print('cache樣本數(shù):',len(cache),'最大用時(shí):',max(cache),'最小用時(shí):',min(cache),'cache均值:','%.2f' % np.mean(cache))
print('emqt樣本數(shù)',len(emqt),'最大用時(shí):',max(emqt),'最小用時(shí):',min(emqt),'emqt均值:','%.2f' % np.mean(emqt))
print('push樣本數(shù)',len(push),'最大用時(shí):',max(push),'最小用時(shí):',min(push),'push均值:','%.2f' % np.mean(push))
print('all樣本數(shù)',len(all),'最大用時(shí):',max(all),'最小用時(shí):',min(all),'all均值:','%.2f' % np.mean(all))
print('mysql樣本數(shù)',len(mysql),'最大用時(shí):',max(mysql),'最小用時(shí):',min(mysql),'mysql均值:','%.2f' % np.mean(mysql))


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容