本篇內(nèi)容主要講解“Hive中的中位數(shù)是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“Hive中的中位數(shù)是什么”吧!
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名注冊、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、忠縣網(wǎng)站維護、網(wǎng)站推廣。
關(guān)于求解中位數(shù),我們知道在Python中直接有中位數(shù)處理函數(shù)(mean),比如在Python中求解一個中位數(shù),代碼很簡單。
Python計算中位數(shù)
import numpy as np
nums = [1.1,2.2,3.3,4.4,5.5,6.6]
#均值
np.mean(nums)
#中位數(shù)
np.median(nums)
在hive中沒有直接提供相關(guān)的mean函數(shù),但官方提供了兩個UDAF,percentile和percentile_approx。
我們看下官方是怎么說的
DOUBLEpercentile(BIGINT col, p)Returns the exact pthpercentile of a column in the group (does not work with floating point types). p must be between 0 and 1. NOTE: A true percentile can only be computed for integer values. Use PERCENTILE_APPROX if your input is non-integral.
arraypercentile(BIGINT col, array(p1[, p2]...))Returns the exact percentiles p1, p2, ... of a column in the group (does not work with floating point types). pimust be between 0 and 1. NOTE: A true percentile can only be computed for integer values. Use PERCENTILE_APPROX if your input is non-integral.
DOUBLEpercentile_approx(DOUBLE col, p [, B])Returns an approximate pthpercentile of a numeric column (including floating point types) in the group. The B parameter controls approximation accuracy at the cost of memory. Higher values yield better approximations, and the default is 10,000. When the number of distinct values in col is smaller than B, this gives an exact percentile value.
arraypercentile_approx(DOUBLE col, array(p1[, p2]...) [, B])Same as above, but accepts and returns an array of percentile values instead of a single one.
請注意,官方文檔上說了一句話:NOTE: A true percentile can only be computed for integer values. Use
PERCENTILE_APPROX if your input is non-integral.
也就是說,真正的中位數(shù)只能用percentile來計算,輸入需要為整數(shù)類型,使用percentile_approx(輸入為浮點型)計算得到的并不是真正的中位數(shù),也就是所說的近似中位數(shù),經(jīng)過大量數(shù)據(jù)驗證,有時候這個近似中位數(shù)和真正的中位數(shù)差別還是很大的。
如何對有小數(shù)的數(shù)據(jù)求取中位數(shù)呢?
可以把小數(shù)轉(zhuǎn)換為整數(shù),然后再求取中位數(shù)(如先??乘10000)
sparksql中也是如此求取中位數(shù)的,趕快去試一試吧!
到此,相信大家對“Hive中的中位數(shù)是什么”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
本文標(biāo)題:Hive中的中位數(shù)是什么
文章來源:http://aaarwkj.com/article8/iiggip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、商城網(wǎng)站、域名注冊、品牌網(wǎng)站建設(shè)、網(wǎng)站改版、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)