Ai
1 Star 0 Fork 1

Owen/Python-causalml

forked from 连享会/Python-causalml 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_utils.py 692 Bytes
一键复制 编辑 原始数据 按行查看 历史
import numpy as np
from causalml.inference.meta.utils import get_weighted_variance
def test_weighted_variance():
x = np.array([1, 2, 3, 4, 5])
sample_weight_equal = np.ones(len(x))
var_x = get_weighted_variance(x, sample_weight_equal)
# should get the same variance with equal sample_weight
assert var_x == x.var()
x1 = np.array([1, 2, 3, 4, 4, 5, 5])
sample_weight_equal = np.ones(len(x1))
sample_weight = [1, 1, 1, 2, 2]
var_x2 = get_weighted_variance(x, sample_weight)
var_x1 = get_weighted_variance(x1, sample_weight_equal)
# should get the same variance by duplicate the observation based on the sample weight
assert var_x1 == var_x2
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/owen560/Python-causalml.git
git@gitee.com:owen560/Python-causalml.git
owen560
Python-causalml
Python-causalml
v0.12.0

搜索帮助