I am experimenting with platform interoperability between Mathematica and R.

My aim is to create an untrained Neural Network using Mathematica, export this network in MXNet format as a .json file, and import this network into R for a classification problem.

Creating the Network in Mathematica

Here i have created a basic neural network - this network is untrained. I have exported the network alongside the network parameters.

In mathematica the code is as follows.

dec=NetDecoder["Class",{"Chronic Kidney Disease","No Kidney Disease"}]

net = 
  NetChain[{BatchNormalizationLayer[], LinearLayer[20], Ramp, 
    DropoutLayer[0.1], LinearLayer[2], SoftmaxLayer[]},
   "Input" -> 24, "Output" -> dec

There are 24 feature variables for the input and the output is the netdecoder. I then export this network.

Export["net.json", net, "MXNet"]

This produces two files, one with the network, and another with the parameters. By using FilePrint we can visualise this


which returns


Importing the Network into R

Now we have an untrained network as a .json file in MXNet format.

We can import this using:

mydata <- fromJSON(file="net.json")

The Problem

Im not sure how to process the exported net in R. Is it possible to use the imported untrained network from Mathematica, to then be used in R to train on some data?

  • 1
    $\begingroup$ Isn't your question about R more than about Mathematica? From the description of your aims, it seems that you have already completed the MMA parts successfully. $\endgroup$
    – MarcoB
    Jun 10, 2020 at 16:42
  • $\begingroup$ Yes it is, I was hoping someone had encountered this cross-platform problem before when using MMA. $\endgroup$
    – isaac5122
    Jun 10, 2020 at 17:08
  • $\begingroup$ You may have more luck e.g. on StackOverflow with R-specific questions. See for instance stackoverflow.com/search?q=%5Br%5D+neural+network+train $\endgroup$
    – MarcoB
    Jun 10, 2020 at 18:22


Your Answer

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