以分位数中一个常见例子四分位数(quartile)为例(这个已经排序好了): 1,1,3,6,7,12,14,17,25,28,29 其中第一四分位数: Q1 = (11 + 1)* 1 / 4 = 3 R中可以调用quantile ()函数: a <- c(2,3,1,4,5,6,7,9,2) #四分之一位数 quantile(a, 0.25) # 其结果等同于 sort(a)[2] 百分分数是把数据分成100等份后所获得的数。
分位数(Quantile),亦称分位点,是指将一个随机变量的概率分布范围分为几个等份的数值点,常用的有中位数(即二分位数)、四分位由3个部分组成(第25、50和75个百分位,常用于箱形图)和百分位数等。 .data mod = smf.quantreg("foodexp ~ income", data) res = mod.fit(q=0.5) print(res.summary()) 我们可以看看quantile /score return score @staticmethod def quantile_loss(y_true,y_pred,alpha,delta,threshold (y_true, y_pred, alpha): score = XGBQuantile.quantile_cost(x=y_true-y_pred,alpha=alpha) score = np.sum(score) return score @staticmethod def quantile_cost(x, alpha): return (alpha
作者:disksing histogram_quantile 是 Prometheus 特别常用的一个函数,比如经常把某个服务的 P99 响应时间来衡量服务质量。 histogram 场景下的 quantile 前面的内容都是从 quantile 的定义出发的,并不限于 Prometheus 平台。 具体针对 Prometheus 里的 histogram_quantile,还有一些要注意的点。 如果 bucket 设置的不合理,会产生不符合预期的 quantile 结果。 因此如果观察到 histogram_quantile 曲线是笔直的水平线,很可能就是 bucket 设置不合理了。
r = lp("min", c(rep(1,2*n),0), tail(r$solution,1) [1] 1.01523 分位数 当然,我们可以将之前的代码改编为分位数 tau = .3 quantile
def quantile_turnover(quantile_factor, quantile, period=1): 我们来看一下这个计算出来的是什么:某一层因子中,某个股票之前不在这个层 参数解释: quantile_factor : pd.Series 日期、股票名为index,因子层序号为value的series,也就是factor_data['factor_quantile'] ,所以,我们先把quantile_factor = factor_data['factor_quantile']定义好。 quantile_turnover = pd.concat([alphalens.performance.quantile_turnover(quantile_factor, q, turnover_period def plot_top_bottom_quantile_turnover(quantile_turnover, period=1, ax=None): top和bottom层的换手率图。
="0.5"} NaN nginx_http_response_time_seconds{app="default",bucket="",method="GET",status="200",quantile ="0.9"} NaN nginx_http_response_time_seconds{app="default",bucket="",method="GET",status="200",quantile 2 nginx_http_response_time_seconds{app="default",bucket="general__lingqu",method="GET",status="200",quantile nginx_http_response_time_seconds{app="default",bucket="general__lingqu",method="HEAD",status="200",quantile nginx_http_response_time_seconds{app="default",bucket="general__lingqu",method="HEAD",status="200",quantile
(data, 0.25) print("Q1:", Q1) Q2 = quantile_p(data, 0.5) print("Q2:", Q2) Q3 = quantile_p(data, 0.75) (data, 0.25) print("Q1:", Q1) Q2 = quantile_p(data, 0.5) print("Q2:", Q2) Q3 = quantile_p(data, 0.75) (data, 0.25) print("Q1:", Q1) Q2 = quantile_p(data, 0.5) print("Q2:", Q2) Q3 = quantile_p(data, 0.75) (.25)) print('Q2:', df.quantile(.5)) print('Q3:', df.quantile(.75)) 计算结果 Q1: 25.5 Q2: 40.0 Q3: 42.5 分位数概念 2. pandas中的quantile
这时,Quantile Loss就派上用场了。因为基于Quantile Loss的回归模型可以提供合理的预测区间,即使是对于具有非常数方差或非正态分布的残差亦是如此。 Quantile回归:虚线表示基于0.05和0.95 分位数损失函数的回归估计 如上所示的Quantile回归代码在下面这个notebook中。 Quantile Loss函数 基于Quantile回归的目的是,在给定预测变量的某些值时,估计因变量的条件“分位数”。 Quantile Loss实际上只是MAE的扩展形式(当分位数是第50个百分位时,Quantile Loss退化为MAE)。 Quantile Loss的思想是根据我们是打算给正误差还是负误差更多的值来选择分位数数值。损失函数根据所选quantile (γ)的值对高估和低估的预测值给予不同的惩罚值。
这时,Quantile Loss就派上用场了。因为基于Quantile Loss的回归模型可以提供合理的预测区间,即使是对于具有非常数方差或非正态分布的残差亦是如此。 橙线表示两种情况下的OLS估计 Quantile回归:虚线表示基于0.05和0.95 分位数损失函数的回归估计 如上所示的Quantile回归代码在下面这个notebook中。 了解Quantile Loss函数 基于Quantile回归的目的是,在给定预测变量的某些值时,估计因变量的条件“分位数”。 Quantile Loss实际上只是MAE的扩展形式(当分位数是第50个百分位时,Quantile Loss退化为MAE)。 Quantile Loss的思想是根据我们是打算给正误差还是负误差更多的值来选择分位数数值。损失函数根据所选quantile (γ)的值对高估和低估的预测值给予不同的惩罚值。
> probs <- c(0.25, 0.5, 0.75) > > Z %>% + summarize(x = mean(x), + quantile = list( quantile(y, probs)), + prob = list(probs)) %>% + unnest(cols = c("quantile", "prob" > Z %>% + summarize(x = mean(x), + quantile = list(quantile(y, probs)), + > Z %>% + summarize(x = mean(x), + quantile = list(quantile(y, probs)), + prob = list(probs)) %>% + unnest(cols = c("quantile", "prob")) %>% + pivot_wider(names_from = "prob",
geom_crossbar(aes(ymin = q025, y = q05, ymax = q075), data = summarise( group_by(little.mcar.p, n), q025 = quantile (p, .025, na.rm = TRUE), q05 = quantile(p, .05, na.rm = TRUE), q075 = quantile(p, .075, na.rm = TRUE aes(ymin = q925, y = q95, ymax = q975), data = summarise( group_by(little.mcar.p.mar, n), q925 = quantile (p, .925, na.rm = TRUE), q95 = quantile(p, .95, na.rm = TRUE), q975 = quantile(p, .975, na.rm = TRUE
这时,Quantile Loss就派上用场了。因为基于Quantile Loss的回归模型可以提供合理的预测区间,即使是对于具有非常数方差或非正态分布的残差亦是如此。 Quantile回归:虚线表示基于0.05和0.95 分位数损失函数的回归估计 如上所示的Quantile回归代码在下面这个notebook中。 Quantile Loss函数 基于Quantile回归的目的是,在给定预测变量的某些值时,估计因变量的条件“分位数”。 Quantile Loss实际上只是MAE的扩展形式(当分位数是第50个百分位时,Quantile Loss退化为MAE)。 Quantile Loss的思想是根据我们是打算给正误差还是负误差更多的值来选择分位数数值。损失函数根据所选quantile (γ)的值对高估和低估的预测值给予不同的惩罚值。
/quantile-normalization-and-inverse-normal-transform/ 也没看太明白,基本上做eQTL分析的论文里方法部分都会写这个,比如开头提到的论文,方法不部分写到 Finally, TPM values were quantile normalized and inverse normal transformed across samples per gene distribution of expression values for each gene, FPKM values of each gene were further normalized using the quantile-quantile Raw expression levels were normalized with quantile–quantile normalization 这篇文章里提供的代码链接 https://github.com """ M = df.values.copy() Q = M.argsort(axis=0) m,n = M.shape # compute quantile
⭐quantile normalization(分位数标准化) 这是一个比较常见的数据标准化处理方法,对于这个方法我画了一张图便于大家理解。 quantile normalizatio总共有三步: 按照数值从大到小的顺序,在每一列里从上到下重新排列每一列中的表达量。 quantile normalization将数据的分位数统一,即把不同样本的数据的分位数对应到相同的值上。 那么实际应用到我们今天的示例数据GSE97508上,quantile normalization后的箱型图是这样的: quantile normalization 可以看到quantile normalization 但是呢,也有研究表明,quantile normalization之后的数据会改变原始数据的分布,造成有些差异基因不显著。
Raw expression levels were normalized with quantile–quantile normalization. 论文里提供了 quantile–quantile normalization 的代码 https://github.com/YaoZhou89/TGG/blob/main/5.Genetic_analysis /scripts/prepare_gene_expression.R quantile_normalisation <- function(df){ df_rank <- apply(df,2,rank distribution of expression values for each gene, FPKM values of each gene were further normalized using the quantile-quantile The top 20 hidden and confounding factors in the expression data, the normal quantile transformed expression
(j,0.75)-np.quantile(j,0.25) for j in dist_all]).argsort()[:40]] genes = adata1.var.index[np.array( [np.quantile(i,0.75)-np.quantile(i,0.25) for i in dist_all]).argsort()[:40]] dict1 = dict(zip(genes (j,0.75)-np.quantile(j,0.25) for j in dist_all]).argsort()[:40]] #genes = adata1.var.index[np.array ([np.quantile(i,0.75)-np.quantile(i,0.25) for i in dist_all]).argsort()[:40]] dict1 = dict(zip(genes .obs.H3_annotation==layer_types[1]].cortical_depth, 0.75))/2 l3_4 = (np.quantile(adata1.obs[adata1.
= [get_historic_quantile_for_norm_vol(normalised_vol, quantile) for quantile in quantiles] stacked_quantiles_and_vol = pd.concat(quantile_points+[normalised_vol], axis=1) quantile_groups = stacked_quantiles_and_vol.apply (calculate_group_for_row, axis=1) return quantile_groups def get_historic_quantile_for_norm_vol (normalised_vol, quantile_point): return normalised_vol.rolling(99999, min_periods=4).quantile(quantile_point ): if np.isnan(vol_quantile): return 1.0 return 2 - 1.5*vol_quantile 下面是基于连续的市场波动变化的交易系统
geom_crossbar(aes(ymin = q025, y = q05, ymax = q075), data = summarise( group_by(little.mcar.p, n), q025 = quantile (p, .025, na.rm = TRUE), q05 = quantile(p, .05, na.rm = TRUE), q075 = quantile(p, .075, na.rm = TRUE aes(ymin = q925, y = q95, ymax = q975), data = summarise( group_by(little.mcar.p.mar, n), q925 = quantile (p, .925, na.rm = TRUE), q95 = quantile(p, .95, na.rm = TRUE), q975 = quantile(p, .975, na.rm = TRUE
这时,Quantile Loss就派上用场了。因为基于Quantile Loss的回归模型可以提供合理的预测区间,即使是对于具有非常数方差或非正态分布的残差亦是如此。 橙线表示两种情况下的OLS估计 Quantile回归:虚线表示基于0.05和0.95 分位数损失函数的回归估计 如上所示的Quantile回归代码在下面这个notebook中。 Quantile Loss函数 基于Quantile回归的目的是,在给定预测变量的某些值时,估计因变量的条件“分位数”。 Quantile Loss实际上只是MAE的扩展形式(当分位数是第50个百分位时,Quantile Loss退化为MAE)。 Quantile Loss的思想是根据我们是打算给正误差还是负误差更多的值来选择分位数数值。损失函数根据所选quantile (γ)的值对高估和低估的预测值给予不同的惩罚值。
1.获得因子平均收益率数据 因子收益率分析的第一个函数定义如下: def mean_return_by_quantile(factor_data, mean_return_by_q_group, std_err = alphalens.performance.mean_return_by_quantile(factor_data, by_group 上面的按日期算均值的mean_ret有一个美丽的用法,就是结合alphalens.plotting.plot_quantile_returns_violin绘制提琴图。 alphalens.plotting.plot_quantile_returns_violin(mean_return_by_q_daily) ? def plot_cumulative_returns_by_quantile(quantile_returns, period=1, ax=None): 参数解释: quantile_returns