# Extract neural network model from ClassifierFunction

I'm very new to Neural Networks and Mathematica 11 (I used MMA8 some time ago) and I'm trying to learn about NN using Mathematica. I'm using MMA 11.2 in a Rapsberry Pi (yes, I know that doing NN in a RP is a terrible idea).

I have some data and I've trained a NN using Classify:

c = Classify[data, Method->"NeuralNetwork"];

Now I would like to extract the trained network from c, to plot it, re-train it, modify it, etc. I have not found how to do that.

In addition, I've noticed that using Classify or Predict takes a lot of time to get started. The actual training is not that long, for my small dataset, but it takes like 15 minutes to get started. Why is that? I understand that Classify or Predict will guess the optimal NN to use, and then train it, may be that is very time-consuming?

Thank you.

• The reason it takes so long to get started is possibly the feature extraction step. Try using FeatureExtractor->"Something" (check the doc for FeatureExtractor for options) and see if it makes a difference. – Carl Lange Jul 7 '18 at 10:33

You can extract the network from the classifier by doing:

net = (First@c)["Model"]["Network"]


Have a look at the rest of (First@c)["Model"] for other information about the network, including initial conditions.

The start of the Classify step may take so long because of your FeatureExtractor settings. Various feature extractors take different amounts of time to complete, and the frontend doesn't appear to report its progress while doing this. Consider using different FeatureExtractors and see if it goes faster or slower - but be warned, it'll definitely have an effect on your classification accuracy.

• Thank you for your comment! Extracting the model works just fine. i've tried different FeatureExtractors and while there are some differences,it still takes several minutes to start. Do all methods, apart from NeuralNetwork, require this feature extraction? Because others start much faster. I've tried a simple data input in the form of real->boolean, so the input is pretty straightforward. – siritinga Jul 7 '18 at 17:46
• Thanks, it looks very interesting but probably I'm learning it wrong. I think I should start with some more basic material. I did a Coursera course about Machine Learning but I see that to build and train a model from scratch I should know more about encoders, decoders, kinds of layers, their rank and dimension, and so on... – siritinga Jul 7 '18 at 17:50
• Regarding slowness: unfortunately that was my best guess. Have you experimented with networks using NetChain? Do they exhibit the same problem? It might be just that the networks are too memory hungry for the Pi, but I really don't know. – Carl Lange Jul 7 '18 at 17:52
• I personally find this guide to be a perpetual source of light whenever I'm stuck with some more basic concepts, maybe it'll help you! – Carl Lange Jul 7 '18 at 17:53
• I tried NetChain with a simple network: NetChain[{LinearLayer[50], LinearLayer[], LogisticSigmoid}]and training starts in seconds. And if I interpret correctly the reported loss, it's better than the one produced by Classify. – siritinga Jul 7 '18 at 17:59