欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Hive中的中位數(shù)是什么

本篇內(nèi)容主要講解“Hive中的中位數(shù)是什么”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Hive中的中位數(shù)是什么”吧!

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)雅安服務(wù)器托管、營(yíng)銷軟件、網(wǎng)站建設(shè)、忠縣網(wǎng)站維護(hù)、網(wǎng)站推廣。

關(guān)于求解中位數(shù),我們知道在Python中直接有中位數(shù)處理函數(shù)(mean),比如在Python中求解一個(gè)中位數(shù),代碼很簡(jiǎn)單。

Python計(jì)算中位數(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ù),但官方提供了兩個(gè)UDAF,percentile和percentile_approx。

我們看下官方是怎么說(shuō)的

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.

請(qǐng)注意,官方文檔上說(shuō)了一句話:NOTE: A true percentile can only be computed for integer values. Use

PERCENTILE_APPROX if your input is non-integral.

也就是說(shuō),真正的中位數(shù)只能用percentile來(lái)計(jì)算,輸入需要為整數(shù)類型,使用percentile_approx(輸入為浮點(diǎn)型)計(jì)算得到的并不是真正的中位數(shù),也就是所說(shuō)的近似中位數(shù),經(jīng)過大量數(shù)據(jù)驗(yàn)證,有時(shí)候這個(gè)近似中位數(shù)和真正的中位數(shù)差別還是很大的。

如何對(duì)有小數(shù)的數(shù)據(jù)求取中位數(shù)呢?

可以把小數(shù)轉(zhuǎn)換為整數(shù),然后再求取中位數(shù)(如先??乘10000)

sparksql中也是如此求取中位數(shù)的,趕快去試一試吧!

到此,相信大家對(duì)“Hive中的中位數(shù)是什么”有了更深的了解,不妨來(lái)實(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ù)是什么
文章來(lái)源:http://chinadenli.net/article8/iiggip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站商城網(wǎng)站域名注冊(cè)品牌網(wǎng)站建設(shè)網(wǎng)站改版全網(wǎng)營(yíng)銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)