Search code examples
microsoft-r

How to save the output from rxNeuralNet (an mlModel) for reuse?


I used rxNeuralNet and got a great result. I'd like to save it for future use.

nnOutput <- rxNeuralNet(formula = savedFormula, data = inputData, 
                        type = "regression", acceleration = "sse")

I can use the nnOutput with rxPredict, and validate my answers.

rxPredict(nnOutput, data = testSet, outData = tempXDF)

Now I want to save the output, so I can reuse it later. (Training time wasn't insignificant.) I can't seem to find any examples on doing so. I've tried:

rxDataStep(inData = nnOutput, outFile = tempXDF, overwrite = TRUE)
rxImport(inData = nnOutput, outFile = tempXDF, overwrite = TRUE)
write.csv(nnOutput, file = "c:\\temp\\temp.csv")

Any suggestions?


Solution

  • If you have SQL Server, you can persist the mode as binary to SQL, by using rxSerializeModel and/or rxWriteObject.

    You can also use the "bog-standard" R serialize function, or save, or saveRDS.