binning.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:expan 作者: zalando 项目源码 文件源码
def _first_interval(x, n_bins):
    """
    Gets the first interval based on the percentiles, 
    either a closed interval containing the same value multiple times
    or a closed-open interval with a different lower and upper bound.
    """
    # calculate the percentiles
    percentiles = np.linspace(0., 100., n_bins + 1)
    bounds = np.percentile(x, q=percentiles, interpolation='higher')
    lower = bounds[0]
    upper = bounds[1]

    if lower == upper:
        return lower, upper, True, True
    else:
        return lower, upper, True, False


#------- private methods for categorical binnings-------#
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号