# Using a classification Neural Net and parameter to ClassifierMeasurements[]

I created and trained a simple neural net, which takes some inputs and produces a 3-class classification. Then I feed it to CM[] function with some test data, and... nothing. Haven't been successful with this no matter what I change about the net or the various function parameters. What am I missing?

• Can you post the data somewhere? Commented Apr 2, 2017 at 14:05
• You can generate sample data which will suit the network with a line like this: data=(#/100-0.5)->If[Total@#>=7257&&Total@#<7736,0,If[Total@#<7257,-1,1]]&/@RandomInteger[100,{50000,150}]; It trains within 1500-2000 rounds to accuracy in excess of 99.5% Commented Apr 3, 2017 at 2:23

For classification, you usually need a softmax layer in order for the default cross-entropy loss function to work.

So to solve your problem, you can just add a SoftmaxLayer to your network:

net = NetInitialize@
NetChain[{3, LogisticSigmoid, 3, SoftmaxLayer[]}, "Input" -> {150},
"Output" -> NetDecoder[{"Class", {-1, 0, 1}}]]

data = Table[RandomReal[1, {150}] -> RandomInteger[{-1, 1}], {5000}];

trained =
NetTrain[net, Take[data, 4500],
ValidationSet -> {Take[data, -500], "Interval" -> 5}]

cm = ClassifierMeasurements[trained, Take[data, -500]];

cm["Accuracy"]
(* 0.324 *)

• Worked great! I was getting my results as 3-tuples of probabilities, then decoding them with the Class decoder, but a SoftmaxLayer[] produced a single class predictor and changed the loss function behind the scenes and that did the trick. Thank you! Commented Apr 3, 2017 at 2:26
• what is "Interval" -> 5 in the option of ValidationSet mean? Commented Jun 16, 2017 at 8:53
• @partida It "specify the interval at which to calculate validation loss", i.e. calculate validation loss every 5 training round. Commented Jun 16, 2017 at 15:18