一个人力资源咨询集团通过网络爬虫采集手段将多个知名招聘网站上发布的求职和招聘等信息准实时采集到自己的库里,形成一个数据量浩大的招聘信息库,跟踪全国招聘和求职的行业、工种、职位、待遇等信息,并通过商业智能系统,开展职业职位供求及趋势等相关统计分析。这家公司竟然用SSAS OLAP Cube多维数据集容纳如此数量级的数据,广告维成员包含了每一个广告条目。该商业智能团队的开发人员咨询如何用MDX求解薪水中位数、四分位数(Median,Quartile)等。

以下是对Median、Q1、Q3等问题的MDX解答:

1、MDX中位数(Median)求解

中位数(median)是对长度为n的系列数据,根据数据大小排列得到的位于[(n+1)/2]位置上的数据。当变量值的项数N为奇数时,处于中间位置的变量值即为中位数;当N为偶数时,中位数则为处于中间位置的2个变量值的平均数,即(M1+M2)/2。中位数是以它在所有标志值中所处的位置确定的全体单位标志值的代表值,不受分布数列的极大或极小值影响,从而在一定程度上提高了中位数对分布数列的代表性。

1、求解所有招聘广告薪水待遇的中位数median.MDX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//商业智能之路(letusbi.com), Begin
 
WITH
 
//采集到的招聘广告条目(薪水测量值非空)
Set RawAdvSet AS
     NonEmpty([Advertisement].[Adv Id].members,[Measures].[Salary Sum ])
 
//将广告条目按照薪水排序
 
Set AdvSet AS
     Order (RawAdvSet, [Measures].[Salary Sum ], DESC )
 
//招聘广告总数
 
Member [measures].[AdvCount] as
     Count (AdvSet)
 
//招聘广告条目中间位置
 
Member [Measures].[MedianReal] as
     ([measures].[AdvCount]-1) * 50 / 100
 
Member [Measures].[MedianInt] as
     Int ([Measures].[MedianReal])
 
Member [Measures].[MedianFrac] as
     [Measures].[MedianReal]- [Measures].[MedianInt]
 
//薪水“中位数”(低)
 
Member [Measures].[MedianLow] as
     ([AdvSet].Item([Measures].[MedianInt]).Item(0),[Measures].[Salary Sum ])
 
//薪水“中位数”(高)
 
Member [Measures].[MedianHigh] as
     ([AdvSet].Item([Measures].[MedianInt] + 1).Item(0),[Measures].[Salary Sum ])
 
//实际得到薪水的中位数
 
Member [Measures].[Salary Median] as
     ([Measures].[MedianLow] * [Measures].[MedianFrac])
     +([Measures].[MedianHigh] * (1 - [Measures].[MedianFrac]))
 
//商业智能之路(letusbi.com), End

2、四分位数(Quartile)求解

四分位数(Quartile)在统计时把所有数值由小到大排列并分成四等份,处于三个分割点位置的得分就是四分位数,分别如下:

第一四分位数 (Q1),又称“较小四分位数”,等于该样本中所有数值由小到大排列后第25%的数字。

第二四分位数 (Q2),又称“中位数”,等于该样本中所有数值由小到大排列后第50%的数字。

第三四分位数 (Q3),又称“较大四分位数”,等于该样本中所有数值由小到大排列后第75%的数字。

第三四分位数与第一四分位数的差距又称四分位距(InterQuartile Range,IQR)。

2、求解所有招聘广告薪水待遇的四分位数quantile.MDX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 1)求解1Q
//商业智能之路(letusbi.com), Begin
 
WITH
 
Set RawAdvSet AS
     NonEmpty([Advertisement].[Adv Id].members,[Measures].[Salary Sum ])
 
Set AdvSet AS
     Order (RawAdvSet, [Measures].[Salary Sum ], DESC )
 
Member [Measures].[1QReal] as
     ([measures].[AdvCount]-1) * 25 / 100
 
Member [Measures].[1QInt] as
     Int ([Measures].[1QReal])
 
Member [Measures].[1QFrac] as
     [Measures].[1QReal]- [Measures].[1QInt]
 
Member [Measures].[1QLow] as
     ([AdvSet].Item([Measures].[1QInt]).Item(0),[Measures].[Salary Sum ])
 
Member [Measures].[1QHigh] as
     ([AdvSet].Item([Measures].[1QInt] + 1).Item(0),[Measures].[Salary Sum ])
 
//实际得到薪水的四分位数quantile(1Q)
 
Member [Measures].[Salary 1Q] as
     ([Measures].[1QLow] * [Measures].[1QFrac])
     +([Measures].[1QHigh] * (1 - [Measures].[1QFrac]))
 
// 2)求解3Q
 
//商业智能之路(letusbi.com), Begin
Member [Measures].[3QReal] as
     ([measures].[AdvCount]-1) * 75 / 100
 
Member [Measures].[3QInt] as
     Int ([Measures].[3QReal])
 
Member [Measures].[3QFrac] as
     [Measures].[3QReal]- [Measures].[3QInt]
 
Member [Measures].[3QLow] as
     ([AdvSet].Item([Measures].[3QInt]).Item(0),[Measures].[Salary Sum ])
 
Member [Measures].[3QHigh] as
     ([AdvSet].Item([Measures].[3QInt] + 1).Item(0),[Measures].[Salary Sum ])
 
//实际得到薪水的四分位数quantile(3Q)
 
Member [Measures].[Salary 3Q] as
     ([Measures].[3QLow] * [Measures].[3QFrac])
     +([Measures].[3QHigh] * (1 - [Measures].[3QFrac]))
 
//商业智能之路(letusbi.com), End

原文链接:
MDX示例:求解中位数、四分位数(median、quartile)

MDX示例:求解中位数、四分位数(median、quartile)的更多相关文章

  1. MDX示例:求解中位数、四分位数(median、quartile)

    一个人力资源咨询集团通过网络爬虫采集手段将多个知名招聘网站上发布的求职和招聘等信息准实时采集到自己的库里,形成一个数据量浩大的招聘信息库,跟踪全国招聘和求职的行业.工种.职位.待遇等信息,并通过商业智 ...

  2. MDX示例:求解众数(mode)

    在统计学中,众数(Mode)是样本观测值在频数分布表中频数最多的那一组的组中值,主要应用于大面积普查研究之中,众数在一组数据中可能会有好几个.简单的说,众数就是一组数据中占比例最多的一个或几个数.MD ...

  3. [Swift]LeetCode295. 数据流的中位数 | Find Median from Data Stream

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

  4. C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4005 访问. 给定两个大小为 m 和 n 的有序数组 nums1 ...

  5. Google 面试题:Java实现用最大堆和最小堆查找中位数 Find median with min heap and max heap in Java

    Google面试题 股市上一个股票的价格从开市开始是不停的变化的,需要开发一个系统,给定一个股票,它能实时显示从开市到当前时间的这个股票的价格的中位数(中值). SOLUTION 1: 1.维持两个h ...

  6. 数据流中的中位数 Find Median from Data Stream

    2019-04-17 16:34:50 问题描述: 问题求解: class MedianFinder { PriorityQueue<Integer> smaller; PriorityQ ...

  7. vertica 中位数函数 MEDIAN 的使用

    中位数函数:MEDIAN 使用表达式:MEDIAN ( expression ) OVER ( [ window‑partition‑clause ] ) 准备测试数据: ), name ), sal ...

  8. 四分位数及matlab实现

    四分位数(quantile),解释及调用形式如下. quantile(x,y,z)的三个参数的说明如下:x表示要求的矩阵或者向量:y的取值为表示要求的分位数,如四分之一中位数0.25,四分之三中位数0 ...

  9. 两个有序数组的中位数(第k大的数)

    问题:两个已经排好序的数组,找出两个数组合并后的中位数(如果两个数组的元素数目是偶数,返回上中位数). 感觉这种题目挺难的,尤其是将算法完全写对.因为当初自己微软面试的时候遇到了,但是没有想出来思路. ...

随机推荐

  1. 类和对象:面向对象编程 - 零基础入门学习Python037

    类和对象:面向对象编程 让编程改变世界 Change the world by program 经过上节课的热身,相信大家对类和对象已经有了初步的认识,但似乎还是懵懵懂懂:好像面向对象编程很厉害,但不 ...

  2. C 产生随机码

    #include<stdio.h>#include<malloc.h>#include<conio.h>#include<stdlib.h>#inclu ...

  3. Rufus-Create bootable USB drives the easy way

    Rufus Create bootable USB drives the easy way Rufus is a utility that helps format and create bootab ...

  4. 酷狗、QQ、天天动听——手机音乐播放器竞品对比

    如果说什么艺术与人们生活最贴近,那应该属音乐了,因此当代人不离身的手机里必然会有自己喜欢的音乐播放器APP存在. 在当今无论PC端还是手机端音乐播放器都越来越同质化,我们应该选择哪款手机音乐播放器?它 ...

  5. qt 拖拽 修改大小(使用了nativeEvent和winEvent)

    http://www.cnblogs.com/swarmbees/p/5621543.html http://blog.sina.com.cn/s/blog_9e59cf590102w3r6.html

  6. 利用好CSS,实现Qt控件美化

    一.CSS概念 级联样式表 (CSS) 包含应用于网页中的元素的样式规则.CSS 样式定义元素的显示方式以及元素在页中的放置位置.可以创建一个通用规则,只要 Web 浏览器遇到一个元素实例,或遇到一个 ...

  7. poj2689:素数筛

    题目大意,给定l和u,求区间[l,u]内的素数中,相邻两个差最大和最小的素数其中 u的范围达到了2e9本质上需要找出n以内的所有素数,使用筛法.先保存50000(大于sqrt(2e9))内的所有素数, ...

  8. java 面试基础典型题及答案

    1.switch能否作用在byte.int.long.String? 答案:switch能作用在byte.int.enum常量, 补充:jdk7可以作用在String上 2.short s = 1; ...

  9. zoj 3811 Untrusted Patrol(bfs或dfs)

    Untrusted Patrol Time Limit: 3 Seconds      Memory Limit: 65536 KB Edward is a rich man. He owns a l ...

  10. hdu 5072 Coprime (容斥)

    Problem Description There are n people standing in a line. Each of them has a unique id number. Now ...