(defun RDR (tbl &key (RuleGenerator #'GenerateRuleMatchNB) (n 2) (ShowRules nil) (ShowABCD nil) (ShowABCDFn #'(lambda (x) (list (abcd-for x) (abcd-a x) (abcd-b x) (abcd-c x) (abcd-d x) (my-fround (pd x)) (my-fround (pf x)) (my-fround (accuracy x)) (my-fround (precision x)) (my-fround (f-measure x)) (my-fround (balance x))))) (ShowABCDFirst '((for a b c d pd pf acc prec f bal))) (noiseLevel .05) (1p nil) (fmod nil) (global nil)) (let ((results) (x -1)) (dolist (fold (folds (table-egs tbl) n :pred 'lt :key #'(lambda (x) (isa x tbl)))) ;(print (format nil "Starting fold ~A of ~A" (fold-index fold) n)) (gc :full t) (incf x) ; (let ((traindata (cross-index (table-copy tbl (stable-sort (subseq (table-egs tbl) 0 (floor (* (/ (length (table-egs tbl)) n) (+ x 1)))) #'RandomPred :key #'(lambda (x) (isa x tbl)))))) ; (testdata (cross-index (table-copy tbl (stable-sort (subseq (table-egs tbl) (ceiling (* (/ (length (table-egs tbl)) n) (+ x 1)))) #'RandomPred :key #'(lambda (x) (isa x tbl))))))) ;(setf testdata traindata) (let ((testdata (cross-index (table-copy tbl (counted-all (fold-train fold))))) (traindata (cross-index (table-copy tbl (counted-all (fold-test fold)))))) (let ((ruleset (Train (make-RDRule :comment "Top Rule" :class (xindex-majority-class traindata) :bad traindata :good (cross-index (table-copy (xindex-table traindata) nil)) :ugly (cross-index (table-copy (xindex-table traindata) nil)) :fn #'(lambda (x) (not (null x)))) noiseLevel (xindex-ns traindata) RuleGenerator 1p global fmod))) ;(print ruleset) (if ShowRules (print (Show ruleset))) (setf results (append (Test ruleset testdata) results)) ;(print (first results)) (if ShowABCD (align (append ShowABCDFirst (mapcar ShowABCDFn (first results))))))) ;(setf (first results) (cons (floor (* (/ (length (table-egs tbl)) n) (+ x 1))) (first results)))) ) (reverse results))) (defun TreeSize (tree) (if (null tree) 0 (+ 1 (TreeSize (RDRule-true tree)) (TreeSize (RDRule-false tree))))) ;;(deftest test-RDR () ; (check ; (every #'(lambda (x) (every #'(lambda (y) (or (numberp y) (abcd-p y))) x)) (RDR (titanic) :n 10)))) (defun my-fround (x &optional (d 2)) (float (/ (round (* x (expt 10 d))) (expt 10 d))))