1
$\begingroup$

I am trying to assess how well a neural network regression model performs on test data. To do this I have used NetMeasurements command.

net1 = NetChain[{LinearLayer[200], ElementwiseLayer[LogisticSigmoid], 
LinearLayer[200], ElementwiseLayer[LogisticSigmoid], LinearLayer[1]}, "Input" -> 40, 
"Output" -> "Scalar"]   

trainednet1 = NetTrain[net1, traindata, All, ValidationSet -> validationdata, 
BatchSize -> Automatic, LossFunction -> MeanSquaredLossLayer[], Method -> "SGD"] 

NetMeasurements[net1, testdata, "Output"]

When I do this, I get the following error message

NetMeasurements::nninit

What could the issue possibly be?

I have wondered if "net1" should be replaced by "trainednet1" in the argument of NetMeasurements. But, then I get another error

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

NetTrain in your example has All as an argument, so it results in a NetTrainResultsObject instead of a neural network. Use trainednet1["TrainedNet"] instead of just trainednet1 to refer to the neural network.

Also, for NetMeasurements, you have to specify that "Output" is a port of the network. Use NetPort["Output"] instead of just "Output".

NetMeasurements[trainednet1["TrainedNet"], testdata, NetPort["Output"]]
$\endgroup$
5
  • $\begingroup$ What you said about the trained net is very helpful. If I also swap the Output measurement to just “RSquared” then it works fine now. However, if I keep Output and use NetPort as you say then I still get an error but it’s about specifying the loss port of the net using LossFunction??? $\endgroup$
    – Gabi23
    Commented Aug 19, 2021 at 23:31
  • $\begingroup$ testdata should be a list of inputs for the neural network, instead of a list of rules (input -> output). With that, NetMeasurements gives you the mean of the outputs given the inputs. Nevertheless, "RSquared" is more likely to be what you are looking for. $\endgroup$ Commented Aug 19, 2021 at 23:39
  • $\begingroup$ You can check and see The wolfram documentation says the data should take the input->output form in the details section of NetMeasurents. $\endgroup$
    – Gabi23
    Commented Aug 19, 2021 at 23:42
  • $\begingroup$ I was hoping to calculate the mean error between the predicted and actual outputs. $\endgroup$
    – Gabi23
    Commented Aug 20, 2021 at 0:02
  • $\begingroup$ Use "MeanDeviation" instead of "RSquared". $\endgroup$ Commented Aug 20, 2021 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.