cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
%3CLINGO-SUB%20id%3D%22lingo-sub-394270%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EHow%20to%20make%20a%20validation%20column%20in%20regular%20JMP%20using%20JSL%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394270%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20there%20is%20a%20%22Make%20Validation%20Column%22%20function%20in%20JMP%20pro%20but%20I%20am%20wondering%20how%20to%20make%20a%20validation%20column%20(with%2025%25%20training%20and%2075%25%20validation)%20using%20JSL%20in%20%3CU%3E%3CSTRONG%3Eregular%20JMP%3C%2FSTRONG%3E%3C%2FU%3E%3F%20Any%20help%20is%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-394270%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EScripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-394313%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20How%20to%20make%20a%20validation%20column%20in%20regular%20JMP%20using%20JSL%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394313%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESubject%20to%20Dan's%20caveats%20regarding%20random%20assignment%2C%20this%20will%20do%20it%20(in%20this%20case%2C%20for%2075%25%20training%20data).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%26lt%3B%26lt%3B%20new%20column%20(%22Validation%22%2C%20nominal%2C%20%26lt%3B%3CSET%20values%3D%22%22%3E%200.75*nrow(dt))))%3B%0A%3C%2FSET%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EWhy%20this%20works%3A%3C%2FP%3E%0A%3CP%3E1)%20The%20(1%3A%3Anrow)%60piece%20creates%20a%20column%20vector%20%5B1%202%203%20...%20nrow(dt)%5D%2C%20and%20transposes%20(using%20the%20%60%20operator)%20it%20into%20a%20row%20vector%20%5B1%2C2%2C3%2C%20...%20nrow(dt)%5D.%3C%2FP%3E%0A%3CP%3E2)%20Then%2C%20this%20row%20vector%20is%20compared%20to%200.75*nrow(dt).%20If%20greater%2C%20assign%201%2C%20if%20not%2C%20assign%200.%20So%2C%20suppose%20we%20have%20nrow(dt)%20%3D%20100.%20Then%20the%20original%20vector%20is%3A%3C%2FP%3E%0A%3CP%3E%5B1%2C%202%2C%203%2C%20...%20%2C%2074%2C%2075%2C%2076%2C%2077%2C%20...%20100%5D.%20After%20the%20comparison%20with%2075%2C%20the%20result%20vector%20is%3A%3C%2FP%3E%0A%3CP%3E%5B0%2C%200%2C%200%2C%20...%20%2C%200%2C%200%2C%201%2C%201%2C%20...%201%5D.%20That%20is%2C%2075%200s%20followed%20by%2025%201s.%3C%2FP%3E%0A%3CP%3E3)%20Randomshuffle%20(%20)%20puts%20the%20contents%20of%20a%20vector%20into%20random%20order...%20so%20the%2075%200s%20and%2025%201s%20(still%20using%20a%20100-row%20table%20as%20an%20example)%20will%20be%20encountered%20in%20random%20fashion.%3C%2FP%3E%0A%3CP%3E4)%20Finally%2C%20the%20%26lt%3B%26lt%3B%20set%20values%20message%20fills%20the%20column%20with%20this%20random%20assortment%20of%2075%200s%20and%2025%201s.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFWIW%2C%20another%20way%20to%20do%20this%20interactively%20is%20to%20select%20Cols%20%26gt%3B%20New%20Columns...%20from%20the%20main%20menu%2C%20then%20fill%20out%20the%20dialog%20as%20below%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22brady_brady_0-1623965977282.png%22%20style%3D%22width%3A%201600px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22brady_brady_0-1623965977282.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22brady_brady_0-1623965977282.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F33650i255A92076C937F0F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22brady_brady_0-1623965977282.png%22%20alt%3D%22brady_brady_0-1623965977282.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECheers%2C%3C%2FP%3E%0A%3CP%3EBrady%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-394293%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20How%20to%20make%20a%20validation%20column%20in%20regular%20JMP%20using%20JSL%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394293%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIt%20is%20pretty%20simple%20to%20do%20interactively.%20The%20JSL%20steps%20should%20be%20straight-forward%20using%20this%20approach%2C%20too.%3C%2FP%3E%0A%3CP%3ECreate%20a%20columns%20called%20Validation.%3C%2FP%3E%0A%3CP%3EFill%20the%20entire%20column%20with%200s.%20A%20zero%20will%20indicate%20a%20training%20set%20observation.%3C%2FP%3E%0A%3CP%3EGo%20to%20Tables%20%26gt%3B%20Subset.%3C%2FP%3E%0A%3CP%3EEnter%20a%20Random-Sampling%20Rate%20of%200.75%20(for%20your%2075%25%20validation%20set).%3C%2FP%3E%0A%3CP%3ECheck%20the%20box%20for%20Link%20to%20Original%20Data%20Table.%3C%2FP%3E%0A%3CP%3EClick%20OK.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20subset%20table%2C%20change%20a%20validation%20field%20from%200%20to%201.%3C%2FP%3E%0A%3CP%3ERight-click%20the%201%20and%20Fill%20to%20end%20of%20Table.%3C%2FP%3E%0A%3CP%3EClose%20the%20subset%20table.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20was%20pretty%20loose%20with%20my%20JSL%20(didn't%20bother%20with%20proper%20scoping%20to%20avoid%20potential%20issues)%2C%20but%20it%20should%20give%20you%20a%20pretty%20good%20start.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%3DCurrent%20Data%20Table()%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22Validation%22%2C%0A%20Numeric%2C%0A%20%22Nominal%22%2C%0A%20Format(%20%22Best%22%2C%2012%20)%0A)%3B%0AFor%20Each%20Row%20(%3AValidation%20%3D%200)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20Subset(%0A%20Output%20Table(%22ValData%22)%2C%0A%20Linked%2C%0A%20Suppress%20formula%20evaluation(%200%20)%2C%0A%20Sampling%20Rate(%200.75%20)%2C%0A%20Selected%20columns%20only(%200%20)%0A)%3B%0AFor%20Each%20Row%20(%3AValidation%20%3D%201)%3B%0A%0AClose(%20%22ValData%22%20)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20Clear%20Select%3B%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENote%20that%20this%20is%20going%20strictly%20with%20a%20random%20assignment.%20Many%20times%20you%20really%20should%20stratify%20the%20validation%20by%20the%20target%20variable.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMy%20approach%20was%20something%20I%20had%20kept%20hidden%20away%20for%20several%20years.%20Brady%20has%20two%20better%20approaches%20down%20below.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
shasheminassab
Level IV

How to make a validation column in regular JMP using JSL?

Hi

 

I think there is a "Make Validation Column" function in JMP pro but I am wondering how to make a validation column (with 25% training and 75% validation) using JSL in regular JMP? Any help is appreciated.

2 REPLIES 2

Re: How to make a validation column in regular JMP using JSL?

It is pretty simple to do interactively. The JSL steps should be straight-forward using this approach, too.

Create a columns called Validation.

Fill the entire column with 0s. A zero will indicate a training set observation.

Go to Tables > Subset.

Enter a Random-Sampling Rate of 0.75 (for your 75% validation set).

Check the box for Link to Original Data Table.

Click OK. 

In the subset table, change a validation field from 0 to 1.

Right-click the 1 and Fill to end of Table.

Close the subset table.

 

I was pretty loose with my JSL (didn't bother with proper scoping to avoid potential issues), but it should give you a pretty good start.

dt=Current Data Table();
dt << New Column( "Validation",
	Numeric,
	"Nominal",
	Format( "Best", 12 )
);
For Each Row (:Validation = 0);

dt << Subset(
	Output Table("ValData"),
	Linked,
	Suppress formula evaluation( 0 ),
	Sampling Rate( 0.75 ),
	Selected columns only( 0 )
);
For Each Row (:Validation = 1);

Close( "ValData" );

dt << Clear Select;

Note that this is going strictly with a random assignment. Many times you really should stratify the validation by the target variable.

 

My approach was something I had kept hidden away for several years. Brady has two better approaches down below.

Dan Obermiller

Re: How to make a validation column in regular JMP using JSL?

Hi,

 

Subject to Dan's caveats regarding random assignment, this will do it (in this case, for 75% training data).

 

dt << new column ("Validation", nominal, <<set values(randomshuffle( (1::nrow(dt))` > 0.75*nrow(dt))));

Why this works:

1) The (1::nrow)`piece creates a column vector [1 2 3 ... nrow(dt)], and transposes (using the ` operator) it into a row vector [1,2,3, ... nrow(dt)].

2) Then, this row vector is compared to 0.75*nrow(dt). If greater, assign 1, if not, assign 0. So, suppose we have nrow(dt) = 100. Then the original vector is:

[1, 2, 3, ... , 74, 75, 76, 77, ... 100]. After the comparison with 75, the result vector is:

[0, 0, 0, ... , 0, 0, 1, 1, ... 1]. That is, 75 0s followed by 25 1s.

3) Randomshuffle ( ) puts the contents of a vector into random order... so the 75 0s and 25 1s (still using a 100-row table as an example) will be encountered in random fashion.

4) Finally, the << set values message fills the column with this random assortment of 75 0s and 25 1s.

 

 

FWIW, another way to do this interactively is to select Cols > New Columns... from the main menu, then fill out the dialog as below:

brady_brady_0-1623965977282.png

 

 

 

 

Cheers,

Brady

Recommended Articles