diff --git a/src/clj_ml/data.clj b/src/clj_ml/data.clj index c25b5d1..99619cd 100644 --- a/src/clj_ml/data.clj +++ b/src/clj_ml/data.clj @@ -95,15 +95,15 @@ (do (if (or (keyword? (first vs)) (string? (first vs))) ;; this is a nominal entry in keyword or string form - (.setValue inst c (key-to-str (first vs))) + (.setValue inst c (name (first vs))) (if (sequential? (first vs)) ;; this is a map of values - (let [k (key-to-str (nth (first vs) 0)) + (let [k (name (nth (first vs) 0)) val (nth (first vs) 1) ik (index-attr inst k)] (if (or (keyword? val) (string? val)) ;; this is a nominal entry in keyword or string form - (.setValue inst ik (key-to-str val)) + (.setValue inst ik (name val)) (.setValue inst ik (double val)))) ;; A double value for the entry (.setValue inst c (double (first vs))))) @@ -124,24 +124,24 @@ (if (map? att) (if (sequential? (first (vals att))) (let [v (first (vals att)) - vfa (reduce (fn [a i] (.addElement a (key-to-str i)) a) + vfa (reduce (fn [a i] (.addElement a (name i)) a) (new FastVector) v)] - (new Attribute (key-to-str (first (keys att))) vfa)) - (new Attribute (key-to-str (first (keys att))) (first (vals att)))) - (new Attribute (key-to-str att))))) + (new Attribute (name (first (keys att))) vfa)) + (new Attribute (name (first (keys att))) (first (vals att)))) + (new Attribute (name att))))) (recur (rest atts) fv)))))) (defn make-dataset "Creates a new dataset, empty or with the provided instances and options" - ([name attributes capacity-or-values & opts] + ([ds-name attributes capacity-or-values & opts] (let [options (first-or-default opts {}) weight (get options :weight 1) class-attribute (get options :class) ds (if (sequential? capacity-or-values) ;; we have received a sequence instead of a number, so we initialize data ;; instances in the dataset - (let [dataset (new ClojureInstances (key-to-str name) (parse-attributes attributes) (count capacity-or-values))] + (let [dataset (new ClojureInstances (name ds-name) (parse-attributes attributes) (count capacity-or-values))] (loop [vs capacity-or-values] (if (empty? vs) dataset @@ -150,7 +150,7 @@ (.add dataset inst)) (recur (rest vs)))))) ;; we haven't received a vector so we create an empty dataset - (new Instances (key-to-str name) (parse-attributes attributes) capacity-or-values))] + (new Instances (name ds-name) (parse-attributes attributes) capacity-or-values))] ;; we try to setup the class attribute if :class with a attribute name or ;; integer value is provided (when (not (nil? class-attribute)) diff --git a/src/clj_ml/data_store.clj b/src/clj_ml/data_store.clj index 866a89f..a522f58 100644 --- a/src/clj_ml/data_store.clj +++ b/src/clj_ml/data_store.clj @@ -14,13 +14,13 @@ (defn keywords-to-strings [format] "Recursively transforms all keywords into strings" (if (keyword? format) - (key-to-str format) + (name format) (if (map? format) (loop [acum {} ks (keys format)] (if (empty? ks) acum - (recur (conj {(key-to-str (first ks)) + (recur (conj {(name (first ks)) (keywords-to-strings (get format (first ks)))} acum) (rest ks)))) diff --git a/src/clj_ml/ui.clj b/src/clj_ml/ui.clj index 32a34d3..0c47770 100644 --- a/src/clj_ml/ui.clj +++ b/src/clj_ml/ui.clj @@ -28,7 +28,7 @@ cols (get dataset-opts :cols) cols-names (dataset-format dataset) vals-map (reduce (fn [acum col] - (let [name (key-to-str (nth cols-names col)) + (let [name (name (nth cols-names col)) vals (map #(nth (instance-to-vector %1) col) dataseq)] (conj acum {name vals}))) {} @@ -44,8 +44,8 @@ plot) (let [this-val (get vals-map (first ks)) the-plot (if (nil? plot) - (box-plot this-val :title title :legend legend :series-label (key-to-str (first ks))) - (do (add-box-plot plot this-val :series-label (key-to-str (first ks))) + (box-plot this-val :title title :legend legend :series-label (name (first ks))) + (do (add-box-plot plot this-val :series-label (name (first ks))) plot))] (recur the-plot (rest ks)))))))) @@ -84,8 +84,8 @@ acum-map dataseq) title (or (get display-opts :title) (str "Dataset '" (dataset-name dataset) "' Scatter Plot (" - (key-to-str (nth cols-names col-0)) " vs " - (key-to-str (nth cols-names col-1)) ")")) + (name (nth cols-names col-0)) " vs " + (name (nth cols-names col-1)) ")")) legend (if (nil? (get display-opts :legend)) true (get display-opts :legend)) should-display (get display-opts :visualize)] (loop [plot nil @@ -100,11 +100,11 @@ the-plot (if (nil? plot) (scatter-plot this-val-0 this-val-1 :title title - :x-label (key-to-str (nth cols-names col-0)) - :y-label (key-to-str (nth cols-names col-1)) - :series-label (key-to-str (first ks)) + :x-label (name (nth cols-names col-0)) + :y-label (name (nth cols-names col-1)) + :series-label (name (first ks)) :legend legend) - (do (add-points plot this-val-0 this-val-1 :series-label (key-to-str (first ks))) + (do (add-points plot this-val-0 this-val-1 :series-label (name (first ks))) plot))] (recur the-plot (rest ks)))))))) diff --git a/src/clj_ml/utils.clj b/src/clj_ml/utils.clj index fa84c54..c27c2ea 100644 --- a/src/clj_ml/utils.clj +++ b/src/clj_ml/utils.clj @@ -14,14 +14,6 @@ MessageDigest))) -(defn key-to-str - "transforms a keyword into a string" - ([k] - (if (= (class k) String) - k - (let [sk (str k)] - (.substring sk 1))))) - (defn first-or-default "Returns the first element in the collection or the default value" ([col default]