(defun efbin-old (data &optional (num.bins 10)) (if (not (numberp (cadar (last (car data))))) (return-from efbin-old data)) (let ((size (floor (/ (length data) num.bins))) (bname nil) (blast 0) (bcurr 0) (sorted (sort data #'< :key #'(lambda (x) (cadar (last x)))))) (dotimes (i (length sorted)) (cond ((= 0 (mod i size)) (if (nth (+ i size -1) sorted) (setf bcurr (cadar (last (nth (+ i size -1) sorted)))) (setf bcurr (cadar (last (nth (- (length sorted) 1) sorted))))) (setf bname (format nil "~a-~a" blast bcurr) blast bcurr))) (setf (cadar (last (nth i sorted))) bname)) sorted)) ;no class right now (defun efbin (dl &optional (num.bins 10) (class.num 2)) (let ((top.row (pop dl)) (bin.size (ceiling (/ (length dl) num.bins))) (bin.name nil) (nextat 0) (ctr 0)) (dotimes (i (- (length (first dl)) 1)) ;;;;new (if (= i (- (length (first dl)) 1)) (setf bin.size (ceiling (/ (length dl) class.num)))) ;;;; (cond ((numberp (nth i (first dl))) (setf dl (sort dl #'< :key #'(lambda (x) (nth i x)))) (setf nextat 0) (setf ctr 0) (dotimes (row (length dl)) ;;(format t "row:~A nextat: ~A~%" row nextat) (cond ((and (>= row nextat) (not (equalp row (- (length dl) 1)))) (if (<= (length dl) (+ nextat bin.size)) (setf nextat (- (length dl) 1)) (setf nextat (+ nextat bin.size))) ;;(format t "first: ~A nextat: ~A~%" (nth i (nth row dl)) (nth i (nth nextat dl))) (setf bin.name (format nil "~ato~a" (nth i (nth row dl)) (nth i (nth nextat dl)))) (incf ctr))) (setf (nth i (nth row dl)) bin.name) ;(format t "~a,~a~%" nextat (length dl)) ;(print bin.name) ;(print (nth i (nth row dl))) )))) (append (list top.row) dl) )) (defun cleanit (dl coltype) "coltype is a list of columns types. n numeric d discrete" (let (nl temprow ctr) (dolist (row dl) (setf temprow nil) (setf ctr 0) (dolist (item row) (if (eql '? item) (if (eql (nth ctr coltype) 'n) (setf item most-negative-fixnum) (setf item 'novalue))) (setf temprow (append temprow `(,item))) (incf ctr)) (setf nl (append nl `(,temprow) ))) nl)) (defun tocsv (dl) (with-open-file (out "new.csv" :direction :output :if-exists :supersede) (dolist (row dl) (format out "~%") (dolist (item row) (format out "~A," item))))) (defun things (dl &optional (filename "results.lisp") (bins 10) (classbins 2)) (let* ((head (pop dl)) (tail (efbin dl bins classbins)) (all (append `(,head) tail))) (with-open-file (out filename :direction :output :if-exists :supersede) (format out "(defun seheultbinned ()~%'~a)" all))))