7
$\begingroup$

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:

(*<|False->0.294872,True->0.705128|>
<|False->0.335242,True->0.664758|>
<|False->0.271804,True->0.728196|>*)

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.

$\endgroup$
3
$\begingroup$

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];

Quit[]

Classify; 

c = Import["c.mx"];

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

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

Notice that you need to call Classify; before importing.

$\endgroup$

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.