<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          NumPy 數(shù)據(jù)歸一化、可視化

          共 2884字,需瀏覽 6分鐘

           ·

          2020-10-13 10:24

          僅使用 NumPy,下載數(shù)據(jù),歸一化,使用 seaborn 展示數(shù)據(jù)分布。

          下載數(shù)據(jù)

          import numpy as np

          url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
          wid = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[1])

          僅提取 iris 數(shù)據(jù)集的第二列 usecols = [1]

          展示數(shù)據(jù)

          array([3.5, 3. , 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3. ,
          3. , 4. , 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3. ,
          3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.1, 3. ,
          3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3. , 3.8, 3.2, 3.7, 3.3, 3.2, 3.2,
          3.1, 2.3, 2.8, 2.8, 3.3, 2.4, 2.9, 2.7, 2. , 3. , 2.2, 2.9, 2.9,
          3.1, 3. , 2.7, 2.2, 2.5, 3.2, 2.8, 2.5, 2.8, 2.9, 3. , 2.8, 3. ,
          2.9, 2.6, 2.4, 2.4, 2.7, 2.7, 3. , 3.4, 3.1, 2.3, 3. , 2.5, 2.6,
          3. , 2.6, 2.3, 2.7, 3. , 2.9, 2.9, 2.5, 2.8, 3.3, 2.7, 3. , 2.9,
          3. , 3. , 2.5, 2.9, 2.5, 3.6, 3.2, 2.7, 3. , 2.5, 2.8, 3.2, 3. ,
          3.8, 2.6, 2.2, 3.2, 2.8, 2.8, 2.7, 3.3, 3.2, 2.8, 3. , 2.8, 3. ,
          2.8, 3.8, 2.8, 2.8, 2.6, 3. , 3.4, 3.1, 3. , 3.1, 3.1, 3.1, 2.7,
          3.2, 3.3, 3. , 2.5, 3. , 3.4, 3. ])

          這是單變量(univariate)長(zhǎng)度為 150 的一維 NumPy 數(shù)組。

          歸一化

          求出最大值、最小值

          smax = np.max(wid)
          smin = np.min(wid)

          In [51]: smax,smin
          Out[51]: (4.4, 2.0)

          歸一化公式:

          s = (wid - smin) / (smax - smin)

          只打印小數(shù)點(diǎn)后三位設(shè)置:

          np.set_printoptions(precision=3)

          歸一化結(jié)果:

          array([0.625, 0.417, 0.5  , 0.458, 0.667, 0.792, 0.583, 0.583, 0.375,
          0.458, 0.708, 0.583, 0.417, 0.417, 0.833, 1. , 0.792, 0.625,
          0.75 , 0.75 , 0.583, 0.708, 0.667, 0.542, 0.583, 0.417, 0.583,
          0.625, 0.583, 0.5 , 0.458, 0.583, 0.875, 0.917, 0.458, 0.5 ,
          0.625, 0.458, 0.417, 0.583, 0.625, 0.125, 0.5 , 0.625, 0.75 ,
          0.417, 0.75 , 0.5 , 0.708, 0.542, 0.5 , 0.5 , 0.458, 0.125,
          0.333, 0.333, 0.542, 0.167, 0.375, 0.292, 0. , 0.417, 0.083,
          0.375, 0.375, 0.458, 0.417, 0.292, 0.083, 0.208, 0.5 , 0.333,
          0.208, 0.333, 0.375, 0.417, 0.333, 0.417, 0.375, 0.25 , 0.167,
          0.167, 0.292, 0.292, 0.417, 0.583, 0.458, 0.125, 0.417, 0.208,
          0.25 , 0.417, 0.25 , 0.125, 0.292, 0.417, 0.375, 0.375, 0.208,
          0.333, 0.542, 0.292, 0.417, 0.375, 0.417, 0.417, 0.208, 0.375,
          0.208, 0.667, 0.5 , 0.292, 0.417, 0.208, 0.333, 0.5 , 0.417,
          0.75 , 0.25 , 0.083, 0.5 , 0.333, 0.333, 0.292, 0.542, 0.5 ,
          0.333, 0.417, 0.333, 0.417, 0.333, 0.75 , 0.333, 0.333, 0.25 ,
          0.417, 0.583, 0.458, 0.417, 0.458, 0.458, 0.458, 0.292, 0.5 ,
          0.542, 0.417, 0.208, 0.417, 0.583, 0.417])

          分布可視化

          import seaborn as sns
          sns.distplot(s,kde=False,rug=True)

          頻率分布直方圖:

          sns.distplot(s,hist=True,kde=True,rug=True)

          帶高斯密度核函數(shù)的直方圖:

          分布 fit 圖

          gamma 分布去 fit :

          from scipy import stats
          sns.distplot(s, kde=False, fit = stats.gamma)

          拿雙 gamma 去 fit:

          from scipy import stats
          sns.distplot(s, kde=False, fit = stats.dgamma)
          閱讀更多此類文章,可關(guān)注下面《Python小例子》:

          瀏覽 57
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  成人啪啪视频在线 | 91丨露脸丨熟女精品 | 91福利免费 | 伊人狠狠爱 | 99亚洲视频|