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, reset

update(predicted, target, **kwargs)

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

By default, this is called once for each batch. :param predicted: the output from the model’s forward function. :param target: actual values :param kwargs: 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) – a 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, reset

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 (tuple, float) – data shift and scale parameters

Returns

copy of metric instance, reset

set_shift_scale(shift_scale)

Adds data denormalization params

Parameters

shift_scale (tuple, float) – 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 (tuple, float) – data shift and scale parameters

Returns

copy of metric instance, reset

set_shift_scale(shift_scale)

Adds data denormalization params.

Parameters

shift_scale (tuple, float) – 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

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. :param predicted: the output from the model’s forward function. :param target: 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

dict of current values of all metrics

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

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

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 (tuple, float) – data shift and scale parameters

update(predicted, target, values=None)

update all metrics.

Parameters
  • predicted – the output from the model’s forward function.

  • target – actual values

  • values (dict) – dict with 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) – dict with matching names (to defined ValueMetrics), containing 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 (tuple, float) – data shift and scale parameters

Returns

copy of metric instance, reset

set_shift_scale(shift_scale)

Adds data denormalization params.

Parameters

shift_scale (tuple, float) – 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