1
$\begingroup$

I am using a Machine learning toolbox on mathematica. I have 8 classes. Training data: for each class, there 100 samples with size 160. I used this code.

trainingset={"class1"->class1train, "class2"->class2train,.....,"class8"->class8train}.
(*note that Dimensions@class**i**train={100,160}. *).
(*for classify, i used the 3rd signature in the documentation*)
classifier = Classify[trainingset, Method -> "NearestNeighbors"];

But, I get this error: Only variable can be predicted. What is this problem?

here is a simple example:

trainingset = {"A" -> {{1, 1}, {1, 2.1}}, "B" -> {{2, 2}, {2.2, 2.5}},
    "C" -> {{3.5, 2}, {3.2, 2}}, "D" -> {{4, 4}, {4.9, 5}}};
c = Classify[trainingset, Method -> "NearestNeighbors"]

I have the same error.

$\endgroup$
  • 1
    $\begingroup$ Or, Classify[Association@trainingset]. The third form uses Association with the classes as the keys. $\endgroup$ – rcollyer Jan 15 '16 at 16:31
  • $\begingroup$ @AntonAntonov, it does not work, you can try it on the example in my question $\endgroup$ – BetterEnglish Jan 15 '16 at 16:31
  • $\begingroup$ @rcollyer, thanks, it works. $\endgroup$ – BetterEnglish Jan 15 '16 at 16:34
  • $\begingroup$ I deleted my original comment because the code was wrong. $\endgroup$ – Anton Antonov Jan 15 '16 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.