How can predictions be bounded to an allowed interval?

clip replaces values outside an interval with the corresponding boundary and preserves the interior.

numpy.clip in practice

Display fractions [-0.2,0.4,1.3] become [0,0.4,1]. Track frequent saturation against raw model outputs because clipping conceals the size of an overshoot.

import numpy as np
np.clip([-0.2,0.4,1.3],0,1)

Result [0.0, 0.4, 1.0]

中文

超界预测怎样限制在允许输出范围?

clip 将低于下限的值设为下限,高于上限的设为上限,区间内值保持原样。

numpy.clip 算例

显示比例 [-0.2,0.4,1.3] 限制到 [0,1] 后为 [0,0.4,1]。如果频繁触边,应检查原模型误差,截断会掩盖偏离幅度。

import numpy as np
np.clip([-0.2,0.4,1.3],0,1)

结果 [0.0, 0.4, 1.0]

References / 参考来源

Keep reading / 继续阅读