cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
showtime287
Level I

Possible to extract Prediction Formula as a one line formula in script?

Hello, 

 

After creating a prediction formula (say from a Neural Network) and a column is created, I can right click on that column and click "formula" and view the created formula.  I then am able to "click and drag" the equation into a text file as a one line equation. 

 

My question: Is it possible to script this process?  I want to save off that formula without having to do the above process every time.  (I already have a script that will run the neural network, etc. just nothing that can save off that single line formula).

 

Thank you for your time!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Possible to extract Prediction Formula as a one line formula in script?

This script is not a general solution but it demonstrations how you could do it:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

nn = dt << Neural(
	Y( :weight ),
	X( :age, :sex, :height ),
	Informative Missing( 0 ),
	Validation Method( "Holdback", 0.3333 ),
	Fit( NTanH( 3 ) )
);

nn << Save Formulas;

formula string   = Char( :H1_1 << Get Formula ) || "\!n";
formula string ||= Char( :H1_2 << Get Formula ) || "\!n";
formula string ||= Char( :H1_3 << Get Formula ) || "\!n";
formula string ||= Char( :Predicted weight << Get Formula );

Save Text File( "My NN Formula.txt", formula string );

View solution in original post

10 REPLIES 10
txnelson
Super User

Re: Possible to extract Prediction Formula as a one line formula in script?

x = col << get formula;

save text file("path to file",x);

 

see:

     Help==>Scripting Index==>Data Table==>Column Scripting

Jim
showtime287
Level I

Re: Possible to extract Prediction Formula as a one line formula in script?

Thanks so much! I will give this a shot.
showtime287
Level I

Re: Possible to extract Prediction Formula as a one line formula in script?

Thanks again for the reply - however, doesnt the "Save Text File" only work for strings? (where you included the 'x').  So I think I will have to try something like x = char(col << get formula).  I'll see if that works.  If you have any other ideas, feel free to let me know!  Thanks. 

txnelson
Super User

Re: Possible to extract Prediction Formula as a one line formula in script?

you are correct, and the adjustment you made should make it work without issue

Jim
showtime287
Level I

Re: Possible to extract Prediction Formula as a one line formula in script?

Hi Jim, 

 

So that works for most equations, but if I'm trying to do that for a formula generated from a Neural Network, the "Get Formula" returns this for the equation/formula:

 

Neural[ ] 

 

Do you know if there is another way to call or get the formula used for a calculation?  It's a long equation so wondering if there is a character limit for "Get Formula".

 

Thanks, 
John

Re: Possible to extract Prediction Formula as a one line formula in script?

Neural saves the fitted model as a series of columns with formulas for each hidden node and for the accumulation of the hidden nodes for each response. It is not the same result as when you fit a linear model.

BTW, I got the formula expression with this message when it was sent to the prediction formula column. It would require substitution with the formulas for the individual hidden nodes (H1 ... Hn) to fully expand it.

showtime287
Level I

Re: Possible to extract Prediction Formula as a one line formula in script?

Thank you, Mark - so is there no current syntax for "grabbing" a Neural Network formula in a script?  As I mentioned previously, what I have been doing is open the formula editor (to view the Neural Network formula), then click and drag the formula to a text file.  Seems like there has to be a way to pull that equation.  Thanks for taking a look!

Re: Possible to extract Prediction Formula as a one line formula in script?

This script is not a general solution but it demonstrations how you could do it:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

nn = dt << Neural(
	Y( :weight ),
	X( :age, :sex, :height ),
	Informative Missing( 0 ),
	Validation Method( "Holdback", 0.3333 ),
	Fit( NTanH( 3 ) )
);

nn << Save Formulas;

formula string   = Char( :H1_1 << Get Formula ) || "\!n";
formula string ||= Char( :H1_2 << Get Formula ) || "\!n";
formula string ||= Char( :H1_3 << Get Formula ) || "\!n";
formula string ||= Char( :Predicted weight << Get Formula );

Save Text File( "My NN Formula.txt", formula string );
showtime287
Level I

Re: Possible to extract Prediction Formula as a one line formula in script?

Thank you, Mark - I really appreciate your time.  I found that I was able to print out (but not to a separate file) the entire formula (using the Show() command) doing something like this:

 

result = Column("Predicted x") >> Get Formula

Show(result); 

 

Once I saw the printed equation matched what I wanted (using the Show() command), I attempted to convert that to a string for using the "Save Text File" command.  However, in converting the formula to a string, it resulted in this output:

 

"."

 

I tested this by trying to convert something simple like "tan(a+b)" to a string, but within the char() command, it attempts to solve "tan(a+b)".  Not sure if that's what's happening to the above.  

 

But I see your proposed solution includes a bit more syntax I wasn't including, so I will give this a shot now.