Subscribe Bookmark RSS Feed

How to save a prediction formula column with a specific name via JSL?

jumper

Community Trekker

Joined:

Oct 7, 2014

Dear all,

 

I am running some generalised linear model via a JSL script.

How can I save the prediction formula to a column with a specific name?

 

All I managed to find (Automate saving of prediction formula using JMP script?) was something like:

GLM = Fit Model (......);

GLM << prediction formula;

 

However:

 

1) can I choose the name of the column which will store the prediction formula? JMP will automatically save it to: "Pred Formula 'Target Variable'"

2) Is this functionality documented anywhere? I found it on the forum above, but not in JMP's documentation

3) Does the same syntax work for other platforms (e.g. partition)?

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
sseligman

Staff

Joined:

Sep 15, 2016

Solution

Ian's reply answers concerns #1 and #3, while user ms answers question #2 about documentation surrounding the JMP Scripting Language (JSL).

 

@ian_jmp:

 

Generally 'Save Prediction Formula' is consistent across platforms. The name(s) of the saved columns are indeed fixed, but you can rename them using things like: 

dt = Open("$SAMPLE_DATA/Big Class.jmp");
cols = dt << GetColumnNames("String");
For(c=1, c<=NItems(cols), c++,
  Column(dt, cols[c]) << SetName("New "||cols[c]);
);

On rare occasions it can be helpful to use 'Get Column Names' before and after the columns are created, comparing the two lists to infer the names of the new columns.

 

@ms:

 

Regarding documentation for JSL, I think that the Scripting Index (Help menu) is a great resource, packed with ready-to-use examples. And yes, << Prediction Formula is there.

 

6 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

Generally 'Save Prediction Formula' is consistent across platforms. The name(s) of the saved columns are indeed fixed, but you can rename them using things like: 

dt = Open("$SAMPLE_DATA/Big Class.jmp");
cols = dt << GetColumnNames("String");
For(c=1, c<=NItems(cols), c++,
  Column(dt, cols[c]) << SetName("New "||cols[c]);
);

On rare occasions it can be helpful to use 'Get Column Names' before and after the columns are created, comparing the two lists to infer the names of the new columns.

 

jumper

Community Trekker

Joined:

Oct 7, 2014

Mmm, it sounds very convoluted. What I have found is that if my target variable is called "My Target", the column will be called "Pred Formula My Target", so I use:


GLM = Fit Model (......);


GLM << prediction formula;


Column("Pred Formula My Target") << Set Name("New Column Name");


How about documentation? Is this properly documented anywhere in the JSL documentation? I haven't managed to find it. I am new to JMP scripting, but first impressions are that it is a powerful language with a convoluted syntax and poor documentation, a bit like R in a way - but I would expect better documentation from a commercial software!

Finally, I create another column which multiplies the prediction by something else:


New Column("My new calculation", Numeric, Formula( :"My saved Prediction" * :another_field ));


where "My saved prediction" has spaces in the name, another_field does not. The formula is calculated correctly, but if I right click on the heading and go to formula, I see an empty box multiplied by another_field. Is this a bug in JMP? Should I have specified the formula differently?

Thank you.

ms

Super User

Joined:

Jun 23, 2011

The empty box may indicate that the column :My saved Prediction (should not be within double quotes) does not exist in the current data table. Check spelling.

Regarding documentation for JSL, I think that the Scripting Index (Help menu) is a great resource, packed with ready-to-use examples. And yes, << Prediction Formula is there.

jumper

Community Trekker

Joined:

Oct 7, 2014

I removed the double quotes from :My Saved prediction and now it all works fine.

Thank you for pointing me to the Scripting Index - very useful!

sseligman

Staff

Joined:

Sep 15, 2016

Solution

Ian's reply answers concerns #1 and #3, while user ms answers question #2 about documentation surrounding the JMP Scripting Language (JSL).

 

@ian_jmp:

 

Generally 'Save Prediction Formula' is consistent across platforms. The name(s) of the saved columns are indeed fixed, but you can rename them using things like: 

dt = Open("$SAMPLE_DATA/Big Class.jmp");
cols = dt << GetColumnNames("String");
For(c=1, c<=NItems(cols), c++,
  Column(dt, cols[c]) << SetName("New "||cols[c]);
);

On rare occasions it can be helpful to use 'Get Column Names' before and after the columns are created, comparing the two lists to infer the names of the new columns.

 

@ms:

 

Regarding documentation for JSL, I think that the Scripting Index (Help menu) is a great resource, packed with ready-to-use examples. And yes, << Prediction Formula is there.

 

markbailey

Staff

Joined:

Jun 23, 2011

Continuing your example:

GLM = Fit Model (......);
pf = GLM << prediction formula;
pf << Set Name( "my name" );

Yes, this approach should work with any of the modeling platforms.

 

Learn it once, use it forever!