4
$\begingroup$

Mathematica 11.3 has the ability to store trained classifier/predictor in the notebook. But how can we restore it in the new session?

Create notebook and measure it's size:

FileSize[NotebookDirectory[] <> CurrentValue["NotebookFileName"]]
(* 12.B *)

Train classifier and store it in the notebook.

Interesting note: the option to store will be proposed only if training time is more than 2 seconds.

SeedRandom[0];
X = RandomReal[{-1, 1}, {100000, 50}];
Y = RandomInteger[{0, 1}, 100000];

c = Classify[X -> Y, Method -> "RandomForest", PerformanceGoal -> "DirectTraining"]

enter image description here

Measure notebook size again:

NotebookSave[]
FileSize[NotebookDirectory[] <> CurrentValue["NotebookFileName"]]
(* 6.18639MB *)

We have no persistent objects in our notebook:

PersistentObjects[All, "Notebook"]
(* {} *)
$\endgroup$
4
$\begingroup$

It's not stored in the PersistentObject system. Instead it's cooked into the notebook at the box level. If you run

NotebookRead@PreviousCell[] /. _DynamicModuleBox -> Nothing

before and after clicking the button you'll see the difference. Alternately if you open it in a text editor that becomes clear.

So just click the button and then evaluate the cell with it in it.

Example

Train classifier and store it in the notebook. Then quit kernel or close notebook and open again. X and Y colored blue because they are uninitialized.

enter image description here

$\endgroup$
  • $\begingroup$ This is great! Thank you. $\endgroup$ – Alexey Golyshev Mar 30 '18 at 7:01

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.