When a robot calibration model represents a measurement as the sum of physically nonnegative contributions, a negative coefficient can be a sign that the unconstrained model used cancellation to match the data. Setting that coefficient to zero after fitting gives a feasible set of coefficients. Its remaining coefficients may still reflect the cancellation, so compare it with a fit that enforces the constraint during optimization.
Use a small example with a checkable answer
Consider three synthetic observations whose values are 3, 2, and 1. The first model column is constant across the observations. The second increases from 1 to 3. The unrestricted fit can match the decreasing observations by subtracting that second column. If both coefficients must be nonnegative, the model can produce a flat or increasing response. The downward trend cannot be reproduced under that constraint.
import numpy as np
from scipy.optimize import nnls
A = np.array([[1., 1.], [1., 2.], [1., 3.]])
y = np.array([3., 2., 1.])
free = np.linalg.lstsq(A, y, rcond=None)[0]
clipped = np.maximum(free, 0)
bounded, residual = nnls(A, y)
assert np.allclose(free, [4, -1])
assert np.allclose(clipped, [4, 0])
assert np.allclose(bounded, [2, 0])
assert np.isclose(np.linalg.norm(A @ clipped - y), np.sqrt(14))
assert np.isclose(residual, np.sqrt(2))
With SciPy 1.18.1 and NumPy 2.5.5, the unconstrained coefficients are 4 and minus 1. Clipping the negative coefficient leaves the prediction at 4 in all three rows. The nonnegative least-squares fit instead predicts 2 in all three rows because it refits the remaining coefficient. The residual norm drops from about 3.742 for the clipped fit to 1.414 for the constrained one. SciPy returns the residual norm, which is the square root of the sum of squared residuals.
Compare the fit with the measurement rationale
Apply nonnegativity only where the chosen coefficients represent quantities that cannot be negative. A signed offset, a change relative to a reference, or a term describing a directional effect may legitimately take either sign. Record what each model column represents and which bounds follow from that interpretation. A zero fitted coefficient can mean that the available observations do not support a positive contribution under the model. It does not establish that the underlying physical effect is absent.
Save the predictions and individual residuals alongside the coefficient vector. In this fixture, the constrained predictions still miss the trend even though they improve on clipping. A similar pattern in a real calibration can prompt a review of the model terms, the measurement ordering, or the conditions under which observations were collected. Give the reviewer the original measurements and the constraint settings so the result can be reproduced.
Sources
SciPy nonnegative least-squares reference for the constrained objective and residual norm
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.nnls.html
NumPy least-squares reference for the unconstrained fit
https://numpy.org/doc/stable/reference/generated/numpy.linalg.lstsq.html