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 line formula in script?

Topic Options

- Start Article
- 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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 21, 2017 1:28 PM
(2968 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!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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 10

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Thanks so much! I will give this a shot.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.