Compute the coefficient of determination for one-dimensional regression targets and predictions:
R2=1−∑i(yi−yˉ)2∑i(yi−y^i)2Here, yi is a target, y^i is its prediction, and yˉ is the mean target. When every target is equal, return 1.0 if every prediction matches its target and 0.0 otherwise. Return the score as a Python float.
Input: y_true = [3, 4, 5], y_pred = [2.9, 4.1, 5.0]
Output: 0.99
Explanation: The residual sum of squares is 0.02 and the total sum of squares is 2, so the score is 1 - 0.02 / 2.
Input: y_true = [1, 1, 1], y_pred = [1, 1, 1]
Output: 1.0
Input: y_true = [1, 1, 1], y_pred = [0, 2, 1]
Output: 0.0
Use np.sum((y_true - y_pred) ** 2) for the residual sum of squares.
Check whether the total sum of squares is zero before applying the fraction.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Compute the coefficient of determination for one-dimensional regression targets and predictions:
R2=1−∑i(yi−yˉ)2∑i(yi−y^i)2Here, yi is a target, y^i is its prediction, and yˉ is the mean target. When every target is equal, return 1.0 if every prediction matches its target and 0.0 otherwise. Return the score as a Python float.
Input: y_true = [3, 4, 5], y_pred = [2.9, 4.1, 5.0]
Output: 0.99
Explanation: The residual sum of squares is 0.02 and the total sum of squares is 2, so the score is 1 - 0.02 / 2.
Input: y_true = [1, 1, 1], y_pred = [1, 1, 1]
Output: 1.0
Input: y_true = [1, 1, 1], y_pred = [0, 2, 1]
Output: 0.0
Use np.sum((y_true - y_pred) ** 2) for the residual sum of squares.
Check whether the total sum of squares is zero before applying the fraction.
Sign in to take notes on this problem
Accepts: array
Accepts: array