metrics.py 436 B

1234567891011121314151617
  1. import numpy as np
  2. def coefficient_of_determination(_y, _predicted):
  3. y = np.asarray(_y)
  4. predicted = np.asarray(_predicted)
  5. y_mean = y.mean()
  6. numerator_sum = 0
  7. denominator_sum = 0
  8. for id_val, val in enumerate(y):
  9. numerator_sum += (predicted[id_val] - y_mean) * (predicted[id_val] - y_mean)
  10. denominator_sum += (val - y_mean) * (val - y_mean)
  11. return numerator_sum / denominator_sum