turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Possible to extract Prediction Formula as a one li...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 21, 2017 1:28 PM
(2162 views)

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!

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 10:37 AM
(3921 views)

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 );
```

Learn it once, use it forever!

10 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 21, 2017 2:54 PM
(2155 views)

x = col << get formula;

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

see:

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

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 21, 2017 3:54 PM
(2149 views)

Thanks so much! I will give this a shot.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 6:51 AM
(2126 views)

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 7:15 AM
(2122 views)

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

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 10:03 AM
(2102 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 10:11 AM
(2097 views)

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.

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 10:15 AM
(2088 views)

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 10:37 AM
(3922 views)

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 );
```

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 22, 2017 11:52 AM
(2061 views)

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.