Skip to content

Commit

Permalink
Extended the signature of JavaTrieClassify to classify Dataset object…
Browse files Browse the repository at this point in the history
…s and lists of lists.
  • Loading branch information
antononcube committed Apr 10, 2018
1 parent 175fc33 commit 5933d4c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions JavaTriesWithFrequencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,31 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
]
];

JavaTrieClassify[tr_, records:(_Dataset|{_List..}), "Decision", opts : OptionsPattern[]] :=
First @* Keys @* TakeLargest[1] /@ JavaTrieClassify[tr, records, "Probabilities", opts];

JavaTrieClassify[tr_, records:(_Dataset|{_List..}), "Probability" -> class_, opts : OptionsPattern[]] :=
Map[Lookup[#, class, 0]&, JavaTrieClassify[tr, records, "Probabilities"] ];

JavaTrieClassify[tr_, records:(_Dataset|{_List..}), "TopProbabilities", opts : OptionsPattern[]] :=
Map[ Select[#, # > 0 &]&, JavaTrieClassify[tr, records, "Probabilities", opts] ];

JavaTrieClassify[tr_, records:(_Dataset|{_List..}), "TopProbabilities" -> n_Integer, opts : OptionsPattern[]] :=
Map[TakeLargest[#, UpTo[n]]&, JavaTrieClassify[tr, records, "Probabilities", opts] ];

JavaTrieClassify[tr_, records:(_Dataset|{_List..}), "Probabilities", opts:OptionsPattern[] ] :=
Block[{clRes, classLabels, stencil},

clRes = Map[ JavaTrieClassify[tr, #, "Probabilities", opts] &, Normal@records ];

classLabels = Union[Flatten[Normal[Keys /@ clRes]]];

stencil = AssociationThread[classLabels -> 0];

KeySort[Join[stencil, #]] & /@ clRes
];


End[] (* `Private` *)

EndPackage[]

0 comments on commit 5933d4c

Please sign in to comment.