2

I was reading this answer and thought I would ask a question since it had been asked ~5 years ago. Now there is a line in the answer where it states that to train the classifier, you can use the code:

cfun = titUnclass["Train", Classify @* Values, #Features -> #Objective &];

I had never seen this "at star" notation before, so I looked it up, and discovered it was called Composition (@*). Now I know for Classify that it can specify several methods, however, written like this, it seems that Mathematica goes through several methods before determining the best to use.

My issue is this: I would like to specify the method, however I do not know enough to figure out how to rewrite this line to do so. I tried

cfun = titUnclass["Train", Classify[Values, Method -> "DecisionTree"], #Features -> #Objective &];

and

Composition[Classify][Values]

but received the error (for both)

Classify::bdfmt: Argument Values should be a rule, a list of rules, or an association. 

If someone could point me in the right direction for tackling this, it would be greatly appreciated.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Illari
  • 399
  • 1
  • 9
  • You misread the notation. Look at the result of FullForm[Classify @* Values]. Then, look at the result of (f @* g)[x]. – J. M.'s missing motivation Apr 25 '20 at 04:33
  • Oh! I see! My mistake. I wrote work around where I use //Normal, but I'm still curious to see how Composition[Classify,Values] would be re-written to include Method. – Illari Apr 25 '20 at 04:36
  • Normally, the function concerned would be something like Classify[Values[stuff]], which you want to modify to Classify[Values[stuff], Method -> "DecisionTree"]. Since you're calling it inside a Dataset[], you'd need to use # and & somewhere in there. – J. M.'s missing motivation Apr 25 '20 at 04:39
  • Thanks for taking the time to comment. – Illari Apr 25 '20 at 04:46
  • 2
    does cfun = titUnclass["Train", (Classify[#,Method->"DecisionTree"]&)@*Values, #Features -> #Objective &]; work? – kglr Apr 25 '20 at 04:52
  • @kglr I just tried it out and yes it did! – Illari Apr 25 '20 at 05:26
  • If you add that as an answer, I will accept it. It is much nicer than my work around, where I got the data from the column, used Normal, wrote it as a in the form {point}->1, etc, then passed into classify... etc etc. You get the idea. I was thinking surely there must be a better way to do this, haha. – Illari Apr 25 '20 at 05:28
  • Jomy, glad it worked. I posted the comment as an answer. – kglr Apr 25 '20 at 05:41

1 Answers1

3

You can try

cfun = titUnclass["Train", (Classify[#, Method->"DecisionTree"]&) @* Values,
   #Features -> #Objective &];
kglr
  • 394,356
  • 18
  • 477
  • 896