snowflake.ml.modeling.metrics.explained_variance_score¶

snowflake.ml.modeling.metrics.explained_variance_score(*, df: DataFrame, y_true_col_names: Union[str, List[str]], y_pred_col_names: Union[str, List[str]], sample_weight_col_name: Optional[str] = None, multioutput: Union[str, _SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]] = 'uniform_average', force_finite: bool = True) → Union[float, ndarray[Any, dtype[float64]]]¶

Explained variance regression score function.

Best possible score is 1.0, lower values are worse.

In the particular case when y_true is constant, the explained variance score is not finite: it is either NaN (perfect predictions) or -Inf (imperfect predictions). To prevent such non-finite numbers to pollute higher-level experiments such as a grid search cross-validation, by default these cases are replaced with 1.0 (perfect predictions) or 0.0 (imperfect predictions) respectively. If force_finite is set to False, this score falls back on the original R^2 definition.

Note:

The Explained Variance score is similar to the R^2 score, with the notable difference that it does not account for systematic offsets in the prediction. Most often the R^2 score should be preferred.

Args:
df: snowpark.DataFrame

Input dataframe.

y_true_col_names: string or list of strings

Column name(s) representing actual values.

y_pred_col_names: string or list of strings

Column name(s) representing predicted values.

sample_weight_col_name: string, default=None

Column name representing sample weights.

multioutput: {‘raw_values’, ‘uniform_average’, ‘variance_weighted’} or array-like of shape (n_outputs,), default=’uniform_average’

Defines aggregating of multiple output values. Array-like value defines weights used to average errors. ‘raw_values’:

Returns a full set of scores in case of multioutput input.

‘uniform_average’:

Scores of all outputs are averaged with uniform weight.

‘variance_weighted’:

Scores of all outputs are averaged, weighted by the variances of each individual output.

force_finite: boolean, default=True

Flag indicating if NaN and -Inf scores resulting from constant data should be replaced with real numbers (1.0 if prediction is perfect, 0.0 otherwise). Default is True, a convenient setting for hyperparameters’ search procedures (e.g. grid search cross-validation).

Returns:
score: float or ndarray of floats

The explained variance or ndarray if ‘multioutput’ is ‘raw_values’.