久久精品国产亚洲高清|精品日韩中文乱码在线|亚洲va中文字幕无码久|伊人久久综合狼伊人久久|亚洲不卡av不卡一区二区|精品久久久久久久蜜臀AV|国产精品19久久久久久不卡|国产男女猛烈视频在线观看麻豆

    1. <style id="76ofp"></style>

      <style id="76ofp"></style>
      <rt id="76ofp"></rt>
      <form id="76ofp"><optgroup id="76ofp"></optgroup></form>
      1. 千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構(gòu)

        手機站
        千鋒教育

        千鋒學習站 | 隨時隨地免費學

        千鋒教育

        掃一掃進入千鋒手機站

        領(lǐng)取全套視頻
        千鋒教育

        關(guān)注千鋒學習站小程序
        隨時隨地免費學習課程

        當前位置:首頁  >  技術(shù)干貨  > Python中的眾數(shù)

        Python中的眾數(shù)

        來源:千鋒教育
        發(fā)布人:xqq
        時間: 2023-07-21 17:03:41 1689930221

        統(tǒng)計眾數(shù)介紹

        在統(tǒng)計學中,在所提供的一組數(shù)據(jù)值中更經(jīng)常出現(xiàn)的值被稱為眾數(shù)。換句話說,具有高頻率或重復出現(xiàn)的數(shù)字或值被稱為眾數(shù)或眾數(shù)值。眾數(shù)是中心趨勢的三個措施之一。另外兩個指標分別是平均值和中位數(shù)。

        例如-

        我們有一套A = { 4,5,6,6,7,8,9} 。由于數(shù)字 6 的頻率較高,因此A 組的眾數(shù)為 6 。因此,對于有限數(shù)量的觀察,很容易找到眾數(shù)。一組數(shù)據(jù)值可能有一個模態(tài)值或多個模態(tài)值,或者根本沒有模態(tài)。連續(xù)概率分布的一種眾數(shù)常被稱為任意值 x,它的概率密度函數(shù)有一個最大局部值,所以任意一個峰值都是一種眾數(shù)。

        Python 中的 mode()函數(shù)

        Python 在處理統(tǒng)計數(shù)據(jù)和處理一組大范圍的數(shù)據(jù)值時,成為了一種非常強大的編程語言。Python 為 統(tǒng)計模塊提供了許多進程相當大數(shù)據(jù)集的功能,而眾數(shù)()功能就是其中之一。眾數(shù)()函數(shù)用于返回給定數(shù)據(jù)集范圍內(nèi)中心數(shù)據(jù)點的穩(wěn)健度量。

        眾數(shù)()函數(shù)是 Python 編程語言的標準統(tǒng)計庫中唯一可以應用于非數(shù)值(標稱)數(shù)據(jù)的函數(shù)。

        讓我們看看 Python 中眾數(shù)函數(shù)的語法。

        語法:

        眾數(shù)()功能的語法如下所示:

        
        statistics.mode(data)
        

        Python 中 mode()函數(shù)的參數(shù)

        眾數(shù)()功能的參數(shù)是數(shù)據(jù)。它可以是一個迭代或序列——例如,列表、元組等等。

        注意:如果數(shù)據(jù)參數(shù)為空,mode()函數(shù)將引發(fā) StatisticsError。

        Python 中 mode()函數(shù)的返回值

        一旦在迭代器(例如,列表、元組等等)中計算了所提供數(shù)據(jù)的眾數(shù),眾數(shù)()函數(shù)將根據(jù)參數(shù)中所提供的數(shù)據(jù)返回一個浮點數(shù)或非數(shù)值(標稱)值。

        讓我們考慮一些基于 Python 編程語言的標準統(tǒng)計庫的眾數(shù)()函數(shù)的例子。

        例 1:找到下面給出的數(shù)據(jù)集的眾數(shù):

        
        # importing the statistics library
        import statistics
        
        # creating the data set
        my_set = [10, 20, 30, 30, 40, 40, 40, 50, 50, 60]
        
        # estimating the mode of the given set
        my_mode = statistics.mode( my_set)
        
        # printing the estimated mode to the users  
        print("Mode of given set of data values is", my_mode)
        

        輸出:

        Mode of given set of data values is 40
        

        說明:

        在上例中,我們導入了統(tǒng)計庫,并創(chuàng)建了一個集合作為 my_set 。然后,我們使用 statistics.mode() 函數(shù)估計給定集合的眾數(shù),并將其值打印給用戶。結(jié)果,該組中具有最高頻率的值被成功打印。

        示例 2:演示 mode()函數(shù)在不同種類的數(shù)據(jù)類型上的工作。

        
        # importing the statistics library
        import statistics
        # importing the fractions module
        from fractions import Fraction as fr
        
        # creating the tuple of positive integer numbers
        data_1 = (20, 30, 30, 40, 50, 50, 50, 60, 70, 70)
        
        # creating the tuple of floating point values
        data_2 = (1.2, 2.3, 2.3, 3.4, 4.5, 4.5, 4.5, 5.6, 5.6, 7.8)
        
        # creating the tuple of fractional numbers
        data_3 = (fr(1,3), fr(1,5), fr(1,5), fr(2,3), fr(3,4), fr(8,9))
        
        # creating the tuple of negative integer numbers
        data_4 = (-9, -8, -7, -7, -7, -6, -5, -5, -4, -2)
        
        # creating the tuple of strings
        data_5 = ("apple", "mango", "mango", "mango", "banana", "guava", "guava")
        
        # estimating the mode of the given datasets
        mode_1 = statistics.mode( data_1)
        mode_2 = statistics.mode( data_2)
        mode_3 = statistics.mode( data_3)
        mode_4 = statistics.mode( data_4)
        mode_5 = statistics.mode( data_5)
        
        # printing the estimated modes to the users  
        print("1\. Mode of First Data set is", mode_1)
        print("2\. Mode of Second Data set is", mode_2)
        print("3\. Mode of Third Data set is", mode_3)
        print("4\. Mode of Forth Data set is", mode_4)
        print("5\. Mode of Fifth Data set is", mode_5)
        

        輸出:

        1\. Mode of First Data set is 50
        2\. Mode of Second Data set is 4.5
        3\. Mode of Third Data set is 1/5
        4\. Mode of Forth Data set is -7
        5\. Mode of Fifth Data set is mango
        

        說明:

        在上例中,我們導入了統(tǒng)計庫和分數(shù)模塊。然后,我們創(chuàng)建了一個不同范圍的元組來檢查眾數(shù)()函數(shù)是否適用于各種數(shù)據(jù)類型。我們已經(jīng)創(chuàng)建了一個由正整數(shù)、浮點值、小數(shù)、負整數(shù)和字符串組成的元組。然后我們使用 statistics.mode() 函數(shù)來計算每個數(shù)據(jù)集的眾數(shù)。然后,我們將這些估計值打印給用戶。

        mode()函數(shù)的一些應用

        眾數(shù)()功能是一個統(tǒng)計功能,通常用于金融行業(yè),以便將價格和價值與以前的記錄進行比較。它還有助于從價格分布集合中計算和預測未來可能的價格。眾數(shù)()功能不單獨使用;然而,除此之外還有另外兩種統(tǒng)計方法,即平均值和中位數(shù)。這三者共同作為一個強大的工具來揭示數(shù)據(jù)的許多方面。

        tags: python教程
        聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
        10年以上業(yè)內(nèi)強師集結(jié),手把手帶你蛻變精英
        請您保持通訊暢通,專屬學習老師24小時內(nèi)將與您1V1溝通
        免費領(lǐng)取
        今日已有369人領(lǐng)取成功
        劉同學 138****2860 剛剛成功領(lǐng)取
        王同學 131****2015 剛剛成功領(lǐng)取
        張同學 133****4652 剛剛成功領(lǐng)取
        李同學 135****8607 剛剛成功領(lǐng)取
        楊同學 132****5667 剛剛成功領(lǐng)取
        岳同學 134****6652 剛剛成功領(lǐng)取
        梁同學 157****2950 剛剛成功領(lǐng)取
        劉同學 189****1015 剛剛成功領(lǐng)取
        張同學 155****4678 剛剛成功領(lǐng)取
        鄒同學 139****2907 剛剛成功領(lǐng)取
        董同學 138****2867 剛剛成功領(lǐng)取
        周同學 136****3602 剛剛成功領(lǐng)取
        相關(guān)推薦HOT
        侯马市| 安达市| 岐山县| 保康县| 浦江县| 环江| 满城县| 乌鲁木齐县| 昌都县| 阿巴嘎旗| 新平| 四平市| 长治市| 谢通门县| 柏乡县| 五大连池市| 台南市| 平谷区| 方城县| 泾川县| 务川| 曲周县| 阜南县| 阳曲县| 威远县| 汶川县| 土默特右旗| 图木舒克市| 新闻| 阜南县| 富顺县| 岢岚县| 建湖县| 青岛市| 乡城县| 濮阳县| 乌拉特中旗| 临泉县| 宁德市| 新闻| 读书|