metrics.scm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. (define-module (metrics))
  2. (use-modules
  3. (dataset))
  4. (define-public accuracy-metric
  5. (lambda (actual-labels predicted-labels)
  6. ;; assumption: actual-labels and predicted-labels have the same length
  7. (let iter ([remaining-actual-labels actual-labels]
  8. [remaining-predicted-labels predicted-labels]
  9. [labels-count 0]
  10. [correct-labels-count 0])
  11. (cond
  12. ;; TODO: Should this not be a column abstraction predicate instead of
  13. ;; ~null?~?
  14. [(dataset-column-empty? remaining-actual-labels)
  15. (/ correct-labels-count labels-count)]
  16. [else
  17. ;; TODO: For the predicted labels we might also want to use dataset
  18. ;; astractions, because it is a result of ~dataset-map~, but on the
  19. ;; other hand, it seems weird to think of the returned predictions as a
  20. ;; dataset. Perhaps we can rewrite it to be a column of a dataset
  21. ;; instead.
  22. (if (= (dataset-column-first remaining-actual-labels)
  23. (car remaining-predicted-labels))
  24. (iter (dataset-column-rest remaining-actual-labels)
  25. (cdr remaining-predicted-labels)
  26. (+ labels-count 1)
  27. (+ correct-labels-count 1))
  28. (iter (dataset-column-rest remaining-actual-labels)
  29. (cdr remaining-predicted-labels)
  30. (+ labels-count 1)
  31. correct-labels-count))]))))