(ns code.report.cliff_noise_report (:use (code.utils utils preprocess)) (:use (code.pls cliff ncliff)) (:use (code.data data)) (:use (code.defect utils search1 cliff_java)) (:use (code.privacy privacy)) (:use (code.report privacy_report)) (:use (incanter core stats io))) ;column 3 in csv is acc ;column 4 in csv is pd ;column 5 in csv is precision ;column 6 in csv is fmeasure ;column 7 in csv is pf ;column 1 in csv is machine learners [5] = [knn] (ml-knn) ;column 2 in csv is training data (td-knn) ;fm is [1 2 6] ;group-by column 1 (gb1) ;(extract-acc-data "./code/vote-output-result.csv" [0 2 3] 'acc) (defn extract-acc-data [result-csv-name a performance-name] ;a for [0 2 3] (let [result (report-file result-csv-name) result1 (sel result :cols a) gb0 (group-by first result1) ml-breastcancer (matrix (second (first (filter #(= 0 (first %)) gb0)))) ml-ecoli (matrix (second (first (filter #(= 1 (first %)) gb0)))) ml-glass (matrix (second (first (filter #(= 2 (first %)) gb0)))) ml-heart-c (matrix (second (first (filter #(= 3 (first %)) gb0)))) ml-hep (matrix (second (first (filter #(= 4 (first %)) gb0)))) ml-iris (matrix (second (first (filter #(= 5 (first %)) gb0)))) ml-labor (matrix (second (first (filter #(= 6 (first %)) gb0)))) ml-lymph (matrix (second (first (filter #(= 7 (first %)) gb0)))) ml-vote (matrix (second (first (filter #(= 8 (first %)) gb0)))) td-breastcancer (group-by #(nth % 1) ml-breastcancer) td-ecoli (group-by #(nth % 1) ml-ecoli) td-glass (group-by #(nth % 1) ml-glass) td-heart-c (group-by #(nth % 1) ml-heart-c) td-hep (group-by #(nth % 1) ml-hep) td-iris (group-by #(nth % 1) ml-iris) td-labor (group-by #(nth % 1) ml-labor) td-lymph (group-by #(nth % 1) ml-lymph) td-vote (group-by #(nth % 1) ml-vote) med-tbl (fn [group-td-data] (loop [td (sort-by first group-td-data) result []] (if (empty? td) result (recur (rest td) (conj result (get-median (last (trans (second (first td)))))))))) ;(save (med-tbl td-breastcancer) (str "me-"test-name".dat") :delim \space))) myans (matrix [(med-tbl td-breastcancer) (med-tbl td-ecoli) (med-tbl td-glass) (med-tbl td-heart-c) (med-tbl td-hep) (med-tbl td-iris) (med-tbl td-labor) (med-tbl td-lymph) (med-tbl td-vote) ]) knn-breastcancer (sel (first myans) :cols [0 1 2 3 4]) cliff-breastcancer (sel (first myans) :cols [5 6 7 8 9]) knn-ecoli (sel (second myans) :cols [0 1 2 3 4]) cliff-ecoli (sel (second myans) :cols [5 6 7 8 9]) knn-glass (sel (nth myans 2) :cols [0 1 2 3 4]) cliff-glass (sel (nth myans 2) :cols [5 6 7 8 9]) knn-heart-c (sel (nth myans 3) :cols [0 1 2 3 4]) cliff-heart-c (sel (nth myans 3) :cols [5 6 7 8 9]) knn-hep (sel (nth myans 4) :cols [0 1 2 3 4]) cliff-hep (sel (nth myans 4) :cols [5 6 7 8 9]) knn-iris (sel (nth myans 5) :cols [0 1 2 3 4]) cliff-iris (sel (nth myans 5) :cols [5 6 7 8 9]) knn-labor (sel (nth myans 6) :cols [0 1 2 3 4]) cliff-labor (sel (nth myans 6) :cols [5 6 7 8 9]) knn-lymph (sel (nth myans 7) :cols [0 1 2 3 4]) cliff-lymph (sel (nth myans 7) :cols [5 6 7 8 9]) knn-vote (sel (nth myans 8) :cols [0 1 2 3 4]) cliff-vote (sel (nth myans 8) :cols [5 6 7 8 9])] [(save (bind-columns (matrix [1 2 3 4 5]) (trans [knn-breastcancer knn-ecoli knn-glass knn-heart-c knn-hep knn-iris knn-labor knn-lymph knn-vote])) (str "./code/report/report-2011-11-03-1/"performance-name"-knn.dat") :delim \space) (save (bind-columns (matrix [1 2 3 4 5]) (trans [cliff-breastcancer cliff-ecoli cliff-glass cliff-heart-c cliff-hep cliff-iris cliff-labor cliff-lymph cliff-vote])) (str "./code/report/report-2011-11-03-1/"performance-name"-cliff.dat") :delim \space)])) ;(extract-acc-data2 "./code/report/report-2011-11-18-1/rs3-output-result.csv" [0 2 7] 'pf) ;(extract-performance-data1 "./code/within/ant13-output-result.csv" [1 2 7] 'fm) (def mylr [1 2 3 4 5]) (def mynb [1 2 3 4 5]) (def myrf [1 2 3 4 5]) ;(save (bind-columns (range 1 11) (rest (trans mylr))) "./within/lr-all.dat") ;(extract-performance-data1 "./within/ant13-output-result.csv" [1 2 7] "ant13" "./within") (defn data-case [x] (case x 'ant13 1 'arc 2 'camel10 3 'poi15 4 'redaktor 5 'skarbonka 6 'tomcat 7 'velocity14 8 'xalan24 9 'xerces12 10 (str "else " x))) (def lr1 (trans [0 0 0 0 0 0])) (def nb1 (trans [0 0 0 0 0 0])) (def rf1 (trans [0 0 0 0 0 0])) (defn extract-performance-data1 [result-csv-name fm test-name test-file-name] ;fm [1 2 7] (let [result (report-file result-csv-name) result1 (sel result :cols fm) gb1 (group-by first result1) ml-nb (matrix (second (first (filter #(= 0 (first %)) gb1)))) ml-lr (matrix (second (first (filter #(= 3 (first %)) gb1)))) ml-rf (matrix (second (first (filter #(= 4 (first %)) gb1)))) ; ml-knn (matrix (second (first (filter #(= 5 (first %)) gb1)))) td-nb (group-by #(nth % 1) ml-nb) td-lr (group-by #(nth % 1) ml-lr) td-rf (group-by #(nth % 1) ml-rf) ; td-knn (group-by #(nth % 1) ml-knn) tbl (fn [group-td-data] (loop [td (sort-by first group-td-data) result []] (if (empty? td) (matrix result) (recur (rest td) ; (conj result (apply vector (cons (first (first td)) (last (trans (second (first td)))))))))))] (conj result (get-median (last (trans (second (first td))))))))))] (def mylr (bind-columns mylr (tbl td-lr))) (def mynb (bind-columns mylr (tbl td-nb))) (def myrf (bind-columns mylr (tbl td-rf))) ;traindata,orig,priv,pcliff1,pcliff2,pcliff4 [(save (tbl td-nb) (str test-file-name"/nb-"test-name".dat") :delim \space) (save (tbl td-lr) (str test-file-name"/lr-"test-name".dat") :delim \space) (save (tbl td-rf) (str test-file-name"/rf-"test-name".dat") :delim \space)] ; [(def lr1 (matrix (data-case test-name) (tbl td-lr))) ; (def nb1 (matrix (data-case test-name) (tbl td-nb))) ; (def rf1 (matrix (data-case test-name) (tbl td-rf)))] )) ; (save (tbl td-knn) (str test-file-name"/knn-"test-name".dat") :delim \space)])) (defn extract-acc-data2 [result-csv-name a performance-name] ;a for [0 2 3] (let [result (report-file result-csv-name) result1 (sel result :cols a) ;gb0 (group-by first result1) ml-rs3 result1 td-rs3 (group-by #(nth % 1) ml-rs3) med-tbl (fn [group-td-data] (loop [td (sort-by first group-td-data) result []] (if (empty? td) result (recur (rest td) (conj result (get-median (last (trans (second (first td)))))))))) myans (matrix [(med-tbl td-rs3) ]) knn-rs3 (sel myans :cols [0 1 2 3 4]) cliff-rs3 (sel myans :cols [5 6 7 8 9]) ] [(save (bind-columns (matrix [1 2 3 4 5]) (trans [knn-rs3])) (str "./code/report/report-2011-11-18-1/"performance-name"-knn.dat") :delim \space) (save (bind-columns (matrix [1 2 3 4 5]) (trans [cliff-rs3])) (str "./code/report/report-2011-11-18-1/"performance-name"-cliff.dat") :delim \space)])) ;for all for rs data (defn extract-acc-data3 [result-csv-name a performance-name] ;a for [0 2 3] (let [result (report-file result-csv-name) result1 (sel result :cols a) ;gb0 (group-by first result1) ml-rs3 result1 td-rs3 (group-by #(nth % 1) ml-rs3) med-tbl (fn [group-td-data] (loop [td (sort-by first group-td-data) result []] (if (empty? td) result (recur (rest td) (conj result (get-median (last (trans (second (first td)))))))))) myans (matrix [(med-tbl td-rs3) ])] [(sel myans :cols [0 1 2 3 4]) (sel myans :cols [5 6 7 8 9])])) ; knn-rs3 (sel myans :cols [0 1 2 3 4]) ; cliff-rs3 (sel myans :cols [5 6 7 8 9]) ; [(save (bind-columns (matrix [1 2 3 4 5]) (trans [knn-rs3])) (str "./code/report/report-2011-11-18-1/"performance-name"-knn.dat") :delim \space) ; (save (bind-columns (matrix [1 2 3 4 5]) (trans [cliff-rs3])) (str "./code/report/report-2011-11-18-1/"performance-name"-cliff.dat") :delim \space)])) (defn extract-acc-data4 [result-csv-name a performance-name] ;a for [3 5] 5=pd within (let [result (report-file result-csv-name) result1 (sel result :cols a) ml-rs3 result1 td-rs3 (group-by #(nth % 0) ml-rs3) med-tbl (fn [group-td-data] (loop [td (sort-by first group-td-data) result []] (if (empty? td) result (recur (rest td) (conj result (get-median (last (trans (second (first td)))))))))) myans (matrix [(med-tbl td-rs3)])] [(sel myans :cols [0 1 2 3 4 5 6 7])])) (def rcns [;"./code/report/report-2012-02-01-1/within/rf/ant13-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/arc-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/camel10-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/poi15-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/redaktor-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/skarbonka-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/tomcat-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/velocity14-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/xalan24-output-result.csv" ;"./code/report/report-2012-02-01-1/within/rf/xerces12-output-result.csv" "./code/report/report-2011-11-18-1/rs3-output-result.csv" "./code/report/report-2011-11-18-1/rs5-output-result.csv" "./code/report/report-2011-11-18-1/rs10-output-result.csv" "./code/report/report-2011-11-18-1/rs20-output-result.csv"]) (defn ead3 [result-csv-names a performance-name] (loop [rcn result-csv-names result []] (if (empty? rcn) (let [;nb-result (trans (map first result))] knn-result (trans (map first result)) cliff-result (trans (map second result))] [(save (bind-columns (matrix [1 2 3 4 5]) knn-result) (str "./code/report/report-2011-11-18-1/"performance-name"-knn.dat") :delim \space) (save (bind-columns (matrix [1 2 3 4 5]) cliff-result) (str "./code/report/report-2011-11-18-1/"performance-name"-cliff.dat") :delim \space)]) (recur (rest rcn) (conj result (extract-acc-data3 (first rcn) a performance-name)))))) ; (ead3 rcns [3 5] 'pd)