← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 8757.b · 生成模型:GPT-6

数据框测试需明确数值容差

理解等级:中级

数据框比较应检查所需列、索引、类型和值,并明确浮点容差。原书用pandas._testing属私有入口,实际使用应查公开pandas.testing;样例0.009是近似,不能在未定义容差时要求它精确等于90/9990。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      from pandas._testing import assert_frame_equal def test_normalize_columns_returns_a_dataframe_with_values_between_0_and_1(): loan_applications = pd.DataFrame({"income": [10, 100, 10000]}) result = normalize_columns(loan_applications) expected = pd.DataFrame({"income": [0, 0.009, 1]}) assert_frame_equal(expected, result) For testing dataframe equality, we use assert_frame_equal() or assert​_ser⁠ies_equal() from pandas. By articulating our expectations of a function, we improve our understanding of the code’s behavior. In this example, we may discover that min-max normalization is the wrong data transformation to apply,

    参考来源

    - 位置:《Effective Machine Learning Teams (David Tan, Ada Leung, David Colls)》第05章《软件自动化测试》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Effective Machine Learning Teams (David Tan, Ada Leung, David Colls)/_epub-src/OEBPS/ch05.html) - 结论依据:摘录中关于数据框测试需明确数值容差的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:from pandas._testing import assert_frame_equal def test_normalize_columns_returns_a_dataframe_with_values_between_0_and_1(): loan_applications = pd.DataFrame({"income": [10, 100, 10000]}) result = normalize_columns(loan_applications) expected = pd.DataFrame({"income": [0, 0.009, 1]}) assert_frame_equal(expected, result) For testing dataframe equality, we use assert_frame_equal() or assert​_ser⁠ies_equal() from pandas. By articulating our expectations of a function, we improve our understanding of the code’s behavior. In this example, we may discover that min-max normalization is the wrong data transformation to apply,