R-Squared Score

MediumMachine LearningMathArray

Description

Given equal-length arrays yTrue (not constant) and yPred, return the coefficient of determination R² = 1 - SSres/SStot, rounded to 4 decimal places.

Examples

Input:yTrue = [1,2,3,4], yPred = [1,2,3,4]
Output:1
Explanation:

Comparing residual error to total variance yields an R-squared of 1.

Input:yTrue = [3,5,7,9], yPred = [2,5,8,8]
Output:0.85
Explanation:

Comparing residual error to total variance yields an R-squared of 0.85.

Input:yTrue = [1,2,3], yPred = [2,2,2]
Output:0
Explanation:

Comparing residual error to total variance yields an R-squared of 0.

Constraints

  • 2 ≤ yTrue.length ≤ 10⁴
  • yTrue is not constant

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.