|
8 | 8 | [scicloj.ml.tribuo] |
9 | 9 | [tablecloth.api :as tc] |
10 | 10 | [tech.v3.dataset :as ds] |
11 | | - [tech.v3.dataset.categorical :as dscat] |
12 | | - [tech.v3.dataset.modelling :as ds-mod] |
| 11 | + [tech.v3.dataset.categorical :as ds-cat] |
13 | 12 | [tech.v3.dataset.column-filters :as cf] |
14 | | - [tech.v3.libs.tribuo :as tribuo])) |
15 | | - |
| 13 | + [tech.v3.dataset.modelling :as ds-mod])) |
16 | 14 |
|
17 | 15 | (def iris-target-raw |
18 | 16 | (->> |
|
58 | 56 | model (ml/train (:train-ds split) options) |
59 | 57 | predictions (-> (ml/predict (:test-ds split) model)) |
60 | 58 |
|
61 | | - standardise-fn (:pre-metric-standarisation-fn (ml/options->model-def options)) |
62 | | - |
63 | | - |
64 | 59 |
|
65 | 60 | accuracy (loss/classification-accuracy (-> split :test-ds |
66 | | - dscat/reverse-map-categorical-xforms |
| 61 | + ds-cat/reverse-map-categorical-xforms |
67 | 62 | :species) |
68 | 63 | (-> predictions |
69 | | - dscat/reverse-map-categorical-xforms |
| 64 | + ds-cat/reverse-map-categorical-xforms |
70 | 65 | :species)) |
71 | | - score-fn (:score-fn (ml/options->model-def options)) |
72 | | - score (score-fn model (:test-ds split)) |
73 | | - standardised (standardise-fn predictions (:test-ds split) :discrete) |
74 | | - accuracy-from-standardised (loss/classification-accuracy |
75 | | - (-> standardised :prediction) |
76 | | - (-> standardised :trueth))] |
77 | | - |
78 | | - (t/is (< expected-accuracy accuracy-from-standardised)) |
| 66 | + score (ml/score model |
| 67 | + (cf/prediction predictions) |
| 68 | + (cf/target (:test-ds split)) |
| 69 | + loss/classification-accuracy |
| 70 | + )] |
| 71 | + |
79 | 72 | (t/is (< expected-accuracy score)) |
80 | 73 | (t/is (< expected-accuracy accuracy)) |
81 | 74 | (t/is (= expected-target-val |
|
343 | 336 | (validate-target-symetry :float64)) |
344 | 337 |
|
345 | 338 |
|
| 339 | + |
346 | 340 | (t/deftest xxx |
347 | 341 | (let [iris |
348 | 342 | (make-iris-ds |
|
355 | 349 | :int) |
356 | 350 | split (ds-mod/train-test-split iris {:seed 123}) |
357 | 351 | options {:model-type :scicloj.ml.tribuo/classification |
358 | | - :tribuo-components [{:name "trainer" |
359 | | - :type "org.tribuo.classification.dtree.CARTClassificationTrainer"}] |
| 352 | + :tribuo-components [{:name "nu" |
| 353 | + :type "org.tribuo.classification.libsvm.SVMClassificationType" |
| 354 | + :properties {:type "NU_SVC"}} |
| 355 | + {:name "trainer" |
| 356 | + :type "org.tribuo.classification.libsvm.LibSVMClassificationTrainer" |
| 357 | + :properties {:svmType "nu" |
| 358 | + :probability "true" |
| 359 | + }}] |
360 | 360 | :tribuo-trainer-name "trainer"} |
361 | 361 | model (ml/train (:train-ds split) |
362 | 362 | options) |
363 | 363 |
|
364 | | - p (ml/predict (:test-ds split) model)] |
365 | | - (t/is (= (-> p cf/prediction ds/column-names) [:species])) |
366 | | - (t/is (= (-> p cf/probability-distribution ds/column-names) ["virginica" "setosa" "versicolor"])) |
| 364 | + prediction (ml/predict (:test-ds split) model)] |
| 365 | + |
| 366 | + |
| 367 | + (t/is (= 1.0 |
| 368 | + (ml/score model |
| 369 | + prediction |
| 370 | + (:test-ds split) |
| 371 | + loss/classification-accuracy))) |
| 372 | + |
| 373 | + |
| 374 | + (t/is (= (-> prediction cf/prediction ds/column-names) [:species])) |
| 375 | + (t/is (= (->> prediction cf/probability-distribution ds/column-names (into #{})) #{"virginica" "setosa" "versicolor"})) |
367 | 376 |
|
368 | 377 | (t/is (.equals |
369 | 378 | {:name :species, |
370 | 379 | :datatype :int32, |
371 | 380 | :n-elems 45, |
372 | 381 | :column-type :prediction, |
373 | 382 | :categorical-map {:lookup-table {:versicolor 0, :setosa 1, :virginica 2}, :src-column :species, :result-datatype :int}} |
374 | | - (-> p (cf/prediction) :species meta))))) |
375 | | - |
376 | | - |
| 383 | + (-> prediction (cf/prediction) :species meta))))) |
377 | 384 |
|
378 | 385 |
|
0 commit comments