Skip to content

Commit

Permalink
Fixes #438
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Dec 8, 2024
1 parent b39a095 commit 6239db1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion neanderthal/tech/v3/dataset/tribuo_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
[org.tribuo.regression.xgboost XGBoostRegressionTrainer]))



(defn classification-example-ds
[x]
(let [x (if (integer? x)
Expand Down Expand Up @@ -80,3 +79,11 @@
(is (= "class org.tribuo.classification.dtree.CARTClassificationTrainer"
(str (class trainer))))))


(deftest test-keyword-name
(testing "string name (OK)"
(is (-> (ds/->dataset [{"a" 1}] {:dataset-name "string name"})
(tribuo/make-regression-datasource "a"))))
(testing "keyword name (Error)"
(is (-> (ds/->dataset [{"a" 1}] {:dataset-name :keyword/name})
(tribuo/make-regression-datasource "a")))))
13 changes: 11 additions & 2 deletions src/tech/v3/libs/tribuo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ _unnamed [5 1]:
[org.tribuo.regression.evaluation RegressionEvaluator RegressionEvaluation]
[com.oracle.labs.mlrg.olcut.config ConfigurationManager]
[com.oracle.labs.mlrg.olcut.config.json JsonConfigFactory]))


(set! *warn-on-reflection* true)

Expand Down Expand Up @@ -157,13 +157,22 @@ _unnamed [5 1]:
cnames (->double-array (feat-data idx))))
(meta outputs))))

(defn- safe-str
[n]
(cond (string? n)
n
(or (keyword? n) (symbol? n))
(if-let [nn (namespace n)]
(str nn "/" (name n))
(str (name n)))))


(defn- ds->datasource
^DataSource [ds ds->outputs]
(let [examples (ds->examples ds ds->outputs)
{:keys [output-factory provenance]} (meta examples)
provenance (or provenance
(SimpleDataSourceProvenance. (:name (meta ds)) output-factory))]
(SimpleDataSourceProvenance. (safe-str (:name (meta ds))) output-factory))]
(when-not output-factory
(throw (RuntimeException. "Output factory not present in example metadata")))
(reify DataSource
Expand Down

0 comments on commit 6239db1

Please sign in to comment.