In the Matlab documentation for the Pattern Recognition Network (patternnet()), I am confused about a line of code in the documentation:

[x,t] = iris_dataset;
net = patternnet(10);
net = train(net,x,t);
y = net(x);
perf = perform(net,t,y);
classes = vec2ind(y);

Why is y = net(x)? So, I am assuming that y is the output vector, but why is it set to the column of the input vector, x? I see that the net is the matrix containing the information from the train() function call, but why would it be asking for the inputs?

Reference: http://www.mathworks.com/help/nnet/ref/patternnet.html


The y = net(x) is the inference - using the trained model to predict y given a test input x. I suspect that the model is internally splitting the data of x in training, validation and test sub-sets, but keeping that only as index references. Thus it needs the input vector to pull the test sub-set out of it. See if the example code makes better sense.

  • $\begingroup$ Thanks for the other example. But what I don't understand is why it's being called an output, if it's the neural network's input? Is net(input) returned an array that I'm not understanding? $\endgroup$
    – Gary
    Sep 9 '16 at 0:39
  • $\begingroup$ While being trained, the NN is trying to "discover" a function f(x) such that f(x_train) = t with t being the labels. After the model is trained, the purpose of f(x) is to produce predictions. If x_test is the input, then y = f(x_test) is the output. I think the confusion comes from the vector x containing both x_train and x_test which have completely different purposes. $\endgroup$ Sep 9 '16 at 7:04

Your Answer

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

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