(defun info-splitter (x) (splitter x :debug nil :baseline #'info-baseline :detail #'info-detail)) (defun info (l &optional total) (let ((some (sum l)) (out 0)) (dolist (x l out) (unless (zerop x) (let ((p (/ x some))) (incf out (* (if total (/ some total) 1) -1 p (log p 2)))))))) (defun info-detail (feature range n x) (labels ((class2freq (class) (f x class feature range))) (let* ((classes (xindex-classes-all x)) (class-frequencies (mapcar #'class2freq classes))) (info class-frequencies n)))) (defun info-baseline (x) (labels ((class2freq (class) (f x class))) (let* ((classes (xindex-classes-all x)) (class-frequencies (mapcar #'class2freq classes))) (info class-frequencies (xindex-ns x))))) (deftest test-info-splitter () (check (= 0 ; outlook (info-splitter (cross-index (weather2)))))) (deftest test-id-trainer () (let ((tmp (id-trainer (weather2) :splitter #'info-splitter))) (check (samep tmp " #S(NODE :KEY ROOT :KIDS (#S(NODE :KEY (0 . RAINY) :KIDS (#S(NODE :KEY (3 . TRUE) :KIDS #S(NODE :KEY (THEN . NO) :KIDS NIL)) #S(NODE :KEY (3 . FALSE) :KIDS #S(NODE :KEY (THEN . YES) :KIDS NIL)))) #S(NODE :KEY (0 . SUNNY) :KIDS (#S(NODE :KEY (2 . HIGH) :KIDS #S(NODE :KEY (THEN . NO) :KIDS NIL)) #S(NODE :KEY (2 . NORMAL) :KIDS #S(NODE :KEY (THEN . YES) :KIDS NIL)))) #S(NODE :KEY (0 . OVERCAST) :KIDS (#S(NODE :KEY (THEN . YES) :KIDS NIL))))) ") (eq (id-tester '(sunny nil normal false) tmp) 'yes))))