Core Module Documentation

class neuralprophet.metrics.BatchMetric(name=None, specific_column=None)

Calculates a metric from batch model predictions.

abstract new(specific_column=None)
Parameters

specific_column (int) – Calculate metric only over target at pos

Returns

copy of metric instance

Return type

BatchMetric

update(predicted, target, **kwargs)

Updates the metric’s state using the passed batch output.

By default, this is called once for each batch.

Parameters
  • predicted (pd.DataFrame) – Output from the model’s forward function.

  • target (pd.DataFrame) – actual values

  • kwargs (dict) – Passed on to function that computes the metric.

class neuralprophet.metrics.LossMetric(loss_fn, specific_column=None)

Calculates the average loss according to the passed loss_fn.

Parameters

loss_fn (callable) – Taking a prediction tensor, a target tensor, optionally other arguments, and returns the average loss over all observations in the batch.

new(specific_column=None)
Parameters

specific_column (int) – Calculate metric only over target at pos

Returns

copy of metric instance

Return type

BatchMetric

class neuralprophet.metrics.MAE(specific_column=None, shift_scale=None)

Calculates the mean absolute error.

new(specific_column=None, shift_scale=None)
Parameters
  • specific_column (int) – Calculate metric only over target at pos

  • shift_scale (float, tuple) – Data shift and scale parameters

Returns

Copy of metric instance

Return type

MAE

set_shift_scale(shift_scale)

Adds data denormalization params

Parameters

shift_scale (float, tuple) – Data shift and scale parameters

class neuralprophet.metrics.MSE(specific_column=None, shift_scale=None)

Calculates the mean squared error.

new(specific_column=None, shift_scale=None)
Parameters
  • specific_column (int) – Calculate metric only over target at pos

  • shift_scale (float, tuple) – Data shift and scale parameters

Returns

copy of metric instance

Return type

MSE

set_shift_scale(shift_scale)

Adds data denormalization params.

Parameters

shift_scale (float, tuple) – Data shift and scale parameters

class neuralprophet.metrics.Metric(name=None)

Base class for all Metrics.

compute(save=False)

Calculates the current value of the metric

Parameters

save (bool) – Whether to add the current value to stored_values

Returns

Current value of the metric

Return type

float

print_stored()

Nice-prints stored values

reset(hard=False)

Resets the metric to it’s initial state.

By default, this is called at the start of each epoch.

set_shift_scale(shift_scale)

placeholder for subclasses to implement if applicable

abstract update(predicted, target)

Updates the metric’s state using the passed batch output.

By default, this is called once for each batch.

Parameters
  • predicted (pd.DataFrame) – Output from the model’s forward function.

  • target (pd.DataFrame) – Actual values

class neuralprophet.metrics.MetricsCollection(metrics, value_metrics=None)

Collection of Metrics that performs action over all

add_specific_target(target_pos)

Duplicates BatchMetrics with their version for a specific target.

Parameters

target_pos (int, list) – Index of target to compute metrics over

compute(save=False)

calculates the current value of the metric

Parameters

save (bool) – Whether to add the current value to stored_values

Returns

Current values of all metrics

Return type

dict

get_stored(loc=None)

Creates an OrderedDict from stored metric values

Parameters

loc (int) – If only stored value at this location to be retrieved

Returns

Current values of stored metric values

Return type

OrderedDict

get_stored_as_df(loc=None)

Creates an Dataframe from stored metric values

Parameters

loc (int) – If only stored value at this location to be retrieved

Returns

Current values of stored metric vlaues

Return type

pd.Dataframe

print(loc=None)

Nice-prints stored values

reset(hard=False)

reset all

set_shift_scale(shift_scale)

Adds data denormalization params to applicable metrics

Parameters

shift_scale (float, tuple) – Data shift and scale parameters

update(predicted, target, values=None)

Update all metrics.

Parameters
  • predicted (pd.DataFrame) – Output from the model’s forward function.

  • target (pd.DataFrame) – actual values

  • values (dict) –

    Matching names to defined ValueMetrics

    Note

    If the correct name is not supplied, the metric is not updated.

update_batch(predicted, target)

update BatchMetrics

update_values(values, num)

Update ValueMetrics.

Parameters
  • values (dict) – containing matching names and average values over batch/update step

  • num (int) – number of samples in batch/update step

class neuralprophet.metrics.RMSE(specific_column=None, shift_scale=None)

Calculates the root mean squared error.

new(specific_column=None, shift_scale=None)
Parameters
  • specific_column (int) – Calculate metric only over target at pos

  • shift_scale (float) – Data shift and scale parameters

Returns

copy of metric instance

Return type

RMSE

set_shift_scale(shift_scale)

Adds data denormalization params.

Parameters

shift_scale (float, tuple) – Data shift and scale parameters

class neuralprophet.metrics.ValueMetric(name)

Keeps track of a value as a metric.

update(avg_value, num)
Parameters
  • avg_value (float) – average value over batch/update step

  • num (int) – number of samples in batch/update step