tf.keras.metrics.PearsonCorrelation

Calculates the Pearson Correlation Coefficient (PCC).

Inherits From: MeanMetricWrapper, Mean, Metric

PCC measures the linear relationship between the true values (y_true) and the predicted values (y_pred). The coefficient ranges from -1 to 1, where a value of 1 implies a perfect positive linear correlation, 0 indicates no linear correlation, and -1 indicates a perfect negative linear correlation.

This metric is widely used in regression tasks where the strength of the linear relationship between predictions and true labels is an important evaluation criterion.

name (Optional) string name of the metric instance.
dtype (Optional) data type of the metric result.
axis (Optional) integer or tuple of integers of the axis/axes along which to compute the metric. Defaults to -1.

Example:

pcc = keras.metrics.PearsonCorrelation(axis=-1)
y_true = [[0, 1, 0.5], [1, 1, 0.2]]
y_pred = [[0.1, 0.9, 0.5], [1, 0.9, 0.2]]
pcc.update_state(y_true, y_pred)
pcc.result()
0.9966996338993913

Usage with compile() API:

model.compile(optimizer='sgd',
              loss='mean_squared_error',
              metrics=[keras.metrics.PearsonCorrelation()])

dtype

variables

Methods

add_variable

View source

add_weight

View source

from_config

View source

get_config

View source

Return the serializable config of the metric.

reset_state

View source

Reset all of the metric state variables.

This function is called between epochs/steps, when a metric is evaluated during training.

result

View source

Compute the current metric value.

Returns
A scalar tensor, or a dictionary of scalar tensors.

stateless_reset_state

View source

stateless_result

View source

stateless_update_state

View source

update_state

View source

Accumulate statistics for the metric.

__call__

View source

Call self as a function.