zoukankan      html  css  js  c++  java
  • 标准差

    样本:S = [s1, s2, ..., sn]

    平均值:m = (s1+s2+...+sn)/n

    离差:D = [d1, d2, ..., dn], di = si-m

    离差方:Q = [q1, q2, ..., qn], qi = di**2

    总体方差:v = (q1+q2+...+qn)/n

    总体标准差:s = sqrt(v),方均根

    样本方差:v' = (q1+q2+...+qn)/(n-1)

    样本标准差:s' = sqrt(v'),方均根

    np.std(array)            # 总体标准差
    np.std(array, ddof=1)    # 样本标准差
    # 中位数
    import numpy as np
    import datetime as dt
    
    
    
    def dmy2ymd(dmy):
      """
      把日月年转年月日
      :param day:
      :return:
      """
      dmy = str(dmy, encoding='utf-8')
      t = dt.datetime.strptime(dmy, '%d-%m-%Y')
      s = t.date().strftime('%Y-%m-%d')
      return s
    
    
    dates, opening_prices, 
    highest_prices, lowest_prices, 
    closing_prices, volumes = 
      np.loadtxt('aapl.csv',
                 delimiter=',',
                 usecols=(1, 3, 4, 5, 6, 7),
                 unpack=True,
                 dtype='M8[D],f8,f8,f8,f8,f8',
                 converters={1: dmy2ymd})  # 日月年转年月日
    #总体封盘标准差
    std_c = np.std(closing_prices)
    print(std_c)  # 7.080008325481608
    #总体开盘标准差
    std_o = np.std(opening_prices)
    print(std_o)  # 7.099438350242144
    
    std_c2 = np.std(closing_prices, ddof=1)  # 样本标准差
    print(std_c2)  # 7.201042876260849
    # 手动实现
    m = np.mean(closing_prices) #算数平均值
    d = closing_prices - m #利差
    v = np.mean(d ** 2)#离差方
    s = np.sqrt(v)#总体标准差
    print(s)  # 7.080008325481608
    v2 = (d ** 2).sum() / (d.size - 1)
    s2 = np.sqrt(v2)
    print(s2)  # 样本标准差
    # 7.201042876260849
  • 相关阅读:
    FFOM_秒交易行
    FFOM_脚本源代码
    农药_挂周金币
    保存数据,父页面列表数据更新
    点击按钮不弹出新窗口
    GridView1_RowDeleting 弹出确认对话框
    判断复选框
    获取Guid
    2019 gplt团体程序设计天梯赛总结
    Codeforces Round #550 (Div. 3)E. Median String
  • 原文地址:https://www.cnblogs.com/maplethefox/p/11458659.html
Copyright © 2011-2022 走看看