bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

Hive中的中位數是什么

本篇內容主要講解“Hive中的中位數是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Hive中的中位數是什么”吧!

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名注冊雅安服務器托管、營銷軟件、網站建設、忠縣網站維護、網站推廣。

關于求解中位數,我們知道在Python中直接有中位數處理函數(mean),比如在Python中求解一個中位數,代碼很簡單。

Python計算中位數

import numpy as np

nums = [1.1,2.2,3.3,4.4,5.5,6.6]

#均值

np.mean(nums)

#中位數

np.median(nums)

在hive中沒有直接提供相關的mean函數,但官方提供了兩個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.

也就是說,真正的中位數只能用percentile來計算,輸入需要為整數類型,使用percentile_approx(輸入為浮點型)計算得到的并不是真正的中位數,也就是所說的近似中位數,經過大量數據驗證,有時候這個近似中位數和真正的中位數差別還是很大的。

如何對有小數的數據求取中位數呢?

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

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

到此,相信大家對“Hive中的中位數是什么”有了更深的了解,不妨來實際操作一番吧!這里是創新互聯網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

本文標題:Hive中的中位數是什么
文章來源:http://vcdvsql.cn/article8/iiggip.html

成都網站建設公司_創新互聯,為您提供響應式網站商城網站域名注冊品牌網站建設網站改版全網營銷推廣

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

微信小程序開發