A calibration routine can return two coefficients and still have only enough information to establish their sum. This can happen when two feature columns in a robot log travel together on every recorded run. The fitted values can look reasonable under those conditions, but interpreting each coefficient as a separate physical effect requires more evidence. The residual output from a solver needs its own check, too. Some least-squares interfaces omit the reported residual sum when the fitted design does not meet the conditions for that return value.

Build a fixture with one independent direction

The synthetic fixture below ran with SciPy 1.18.1 and NumPy 2.5.2. It uses four positions and deliberately duplicates the travel column. The response is a made-up measurement of a calibration target, with two departures from a straight line. The departures are chosen so their dot product with the travel vector is zero. That keeps the best-fit sum of the coefficients equal to three and leaves a nonzero prediction error. The fixture is about diagnosing a numerical result. It does not reproduce measurements from a real calibration.

import numpy as np

from scipy.linalg import lstsq

travel = np.array([1., 2., 3., 4.])

design = np.column_stack((travel, travel))

target = 3. * travel + np.array([2., -1., 0., 0.])

weights, reported, rank, singular = np.linalg.lstsq(

design, target, rcond=None

)

error = target - design @ weights

squared_error = error @ error

assert rank == 1 and reported.size == 0

assert np.allclose(weights, [1.5, 1.5])

assert np.allclose(error, [2., -1., 0., 0.])

assert np.isclose(squared_error, 5.)

alternate = weights + np.array([1., -1.])

assert np.allclose(design @ alternate, design @ weights)

assert not np.isclose(alternate[0], weights[0])

weights_qr, residues_qr, rank_qr, spectrum_qr = lstsq(

design, target, cond=1e-12, lapack_driver='gelsy'

)

assert rank_qr == 1 and residues_qr.size == 0 and spectrum_qr is None

assert np.allclose(design @ weights_qr, design @ weights)

The design has two columns and rank one. Only the sum of their coefficients changes the model's predictions for these rows. NumPy gives a minimum-norm solution, which splits the sum equally between two identical columns. Moving one unit of weight from the second column to the first leaves the predictions unchanged. The two coefficient vectors would give different results if a later input could vary one feature while holding the other fixed. This is why a minimum-norm coefficient should not be presented as a physically identified sensor gain by itself.

Compute the residual from the predictions

For this overdetermined but rank-deficient NumPy problem, the returned residual array is empty. Subtracting the fitted values from the original target produces two nonzero errors. Their squared sum is five in the synthetic target's squared units. Reporting the size of the residual array or summing the empty array would miss those errors. If the report needs an error measure, compute the predictions and then use the error definition appropriate to the task. A mean squared error, a raw sum of squared errors, and a worst absolute error answer different questions.

The example also runs SciPy with its gelsy driver and an explicit numerical rank cutoff of 1e-12 for this fixture. That option returns no singular-value array and an empty residual array. The independently computed predictions agree here. In the local run, omitting that explicit cutoff on the SciPy call returned rank two and large coefficients of opposite sign even with duplicated inputs. That observation is specific to the solver and runtime used. It makes the explicit cutoff and the prediction comparison part of the reproducible test. When comparing software versions or solver drivers, record which result fields the program actually receives. Otherwise a change in the availability of a diagnostic can look like a change in model quality. Make sure the comparison uses the same response rows, units, preprocessing, and rank assumptions.

Keep the fit and the experiment problem separate

A rank check describes the feature matrix after preprocessing. If an input log includes copied columns, a constant input that duplicates an intercept, or commands that always rise and fall together, additional rows may preserve the same ambiguity. For separate coefficients, a new collection needs conditions that vary the relevant features independently enough for the intended estimate. That choice belongs in the calibration or test plan. If the goal is only to predict along a documented operating pattern, combining redundant terms can give a more interpretable description of what the data support.

Near dependence is also worth recording. Two columns can be numerically distinct while carrying almost the same variation. Inspect singular values when available and record the rank cutoff. Interpret the values in the context of the feature scales. Changing a feature from meters to millimeters changes the matrix numerically and can affect a threshold-based decision about effective rank. Use consistent documented units or a justified scaling procedure before drawing conclusions across different runs.

Before accepting a report, try a fixture with duplicate columns and a deliberately nonzero error, like the one here. Check that the report acknowledges the rank deficiency and shows the recomputed residual statistic. Then run a case where the columns vary independently. Finally, check any validation data against the conditions the model will face after calibration. If the proposed use includes separate feature changes that the recorded experiment never exercised, state that limit with the coefficients. This makes it clear which predictions can be checked today and which depend on a better-designed collection.

Sources

NumPy, numpy.linalg.lstsq

https://numpy.org/doc/stable/reference/generated/numpy.linalg.lstsq.html

SciPy, scipy.linalg.lstsq

https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.lstsq.html