Let's suppose I have a simple classification problem:

data={{1,"a"}->True,{2,"b"}->True,{3,"b"}->True,{4,"a"}->True, {5,"a"}->False,{6,"b"}->True};
c=Classify[data, Method->"RandomForest"];
c[{5, "b"},"Probabilities"]

This piece of code produces different results occasionally:


I guess it happens because of internal pseudorandom generator calls within RandomForest. How can I make my results replicable (possible give a seed to internal generator)?

Setting a seed using SeedRandom does not make the result deterministic.


1 Answer 1


You can save your trained classifier in .mx file and simply load it in the new session.

data = {{1, "a"} -> True, {2, "b"} -> True, {3, "b"} -> 
    True, {4, "a"} -> True, {5, "a"} -> False, {6, "b"} -> True};
c = Classify[data, Method -> "RandomForest"];
c[{5, "b"}, "Probabilities"]

<|False -> 0.202281, True -> 0.797719|>

Export["c.mx", c];



c = Import["c.mx"];

c[{5, "b"}, "Probabilities"]

<|False -> 0.202281, True -> 0.797719|>

Notice that you need to call Classify; before importing.


Your Answer

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

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