Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用在区间 [0,10] 中具有实值标签的数据集训练线性回归模型。我在测试集上的预测值有一些超过 10 的预测。有没有办法将预测限制为 10。
我正在考虑进行条件检查,如果预测超过 10,我将其明确设置为 10。
有没有更好的办法?
如果y是回归对象predict方法的输出,那么您可以使用 Numpyminimum将其限制为 10:
y
predict
minimum
y = np.minimum(y, 10.)
要将其限制在零以下,请执行
y = np.maximum(np.minimum(y, 10.), 0.)
或者,更短:
y = np.clip(y, 0., 10.)