1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- (use-modules
- ;; SRFI 64 for unit testing facilities
- (srfi srfi-64)
- ;; utils - the code to be tested
- (split-quality-measure)
- ;; Utilities for testing
- (utils test))
- (define PRECISION (expt 10 -9) #;(exact->inexact (expt 10 -9)))
- (test-begin "split-quality-measure-test")
- (test-group
- "gini-index"
- ;; if this test fails, then the gini index of perfect split is not 0.0
- (test-equal "gini-index-1"
- 0.0
- (gini-index
- (list
- (list #(0.5 2.2 3.3 4.4 0)
- #(0.5 2.2 3.3 4.4 0))
- (list #(1.1 2.2 3.3 4.4 1)
- #(1.1 2.2 3.3 4.4 1)))
- 4))
- ;; "gini index of worst split is not 1.0"
- (test-equal "gini-index-2"
- 1.0
- (gini-index (list
- (list #(1.1 2.2 3.3 4.4 0)
- #(1.1 2.2 3.3 4.4 1))
- (list #(1.1 2.2 3.3 4.4 0)
- #(1.1 2.2 3.3 4.4 1)))
- 4))
- ;; "gini index of split is not 0.888888888"
- (test-approximate "test for gini index calculation precision - 2"
- 0.888888888
- (gini-index (list
- (list #(1.1 2.2 3.3 4.4 0)
- #(1.1 2.2 3.3 4.4 1)
- #(1.1 2.2 3.3 4.4 1))
- (list #(1.1 2.2 3.3 4.4 0)
- #(1.1 2.2 3.3 4.4 0)
- #(1.1 2.2 3.3 4.4 1)))
- 4)
- PRECISION))
- (test-group
- "calc-proportion"
- (test-approximate "calc-proportion-1"
- 0.1875
- (calc-proportion
- (list
- #(2.3 1.2 7.2 1)
- #(213.1 34.6 786.1 0)
- #(1 1 1 1)
- #(4.0 -1.1 6.8 1))
- 0
- 3)
- PRECISION))
- (test-end "split-quality-measure-test")
|