ConstantIntensityRegressor

class flexparameterize.regression.constant.ConstantIntensityRegressor

Fits the mean energy intensity of a unit from paired flow and power data.

The simplest zero-degree-of-freedom fit: one input, one output, one coefficient. Rows where either side is null, or where the flow is zero, are dropped, and the coefficient is the mean of the per-row ratios, mean(power / flow) — not a least-squares slope. The mean ratio weights every operating point equally, which is the behaviour an operator expects from an “average kWh per m^3” number, and it recovers a noise-free data set exactly (which is what the round-trip invariant asserts). A least-squares slope through the origin would weight high-flow points more heavily.

Fit results are stored on the instance.

coefficient

The fitted intensity, in the ratio of y’s units to X’s (kW over m^3/hr, i.e. kWh/m^3).

n_samples

Number of rows the fit used, after dropping.

metrics

{"r2": ..., "rmse": ...} of coefficient * flow against the observed power.

data_window

(first, last) index value of the rows used.

input_variable

Column name of the fitted input.

output_variable

Column name of the fitted output.

Example

>>> import pandas as pd
>>> flow = pd.DataFrame({"flow_in": [1.0, 2.0, 4.0]})
>>> power = pd.DataFrame({"power_electrical": [0.5, 1.0, 2.0]})
>>> ConstantIntensityRegressor().fit(flow, power).coefficient
0.5
fit(X: DataFrame, y: DataFrame) → ConstantIntensityRegressor

Fit the mean energy intensity of y against X.

Parameters:
  • X – A one-column DataFrame holding the flow.

  • y – A one-column DataFrame holding the power, sharing X’s index.

Returns:

self, fitted.

Raises:

FlexDataError – If either side is not a DataFrame or does not hold exactly one column, or no row survives dropping nulls and zero-flow rows.

to_fit_result() → FitResult

Return this fit as the shared FitResult shape.

Returns:

The coefficient under COEFFICIENT_NAME, alongside the fit’s metrics, sample count and data window.

Raises:

FlexDataError – If fit() has not been called.

to_surrogate_spec(*, input_units: str = '', output_units: str = '') → SurrogateSpec

Return the fit as a persistable SurrogateSpec.

The one place a constant-intensity fit becomes a spec, which apply_to_model() consumes. Built through make_spec(). A constant intensity sets a process parameter rather than swapping a Constraint, so unlike a real surrogate’s declared units, these are recorded for documentation, not enforced by a build.

Parameters:
  • input_units – Units of the fitted input column, as a string (the caller reads them off the model’s registered variable).

  • output_units – Units of the fitted output column.

Returns:

A SurrogateType.CONSTANT_INTENSITY SurrogateSpec carrying the coefficient under COEFFICIENT_NAME and the fitted column names.

Raises:

FlexDataError – If fit() has not been called.