cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
lala
Level IX

How to copy the list of column contributions of a random forest using a script?

Thanks Experts!

dt = Open( "$SAMPLE_DATA/Diabetes.jmp" );
p= dt << Bootstrap Forest(
	Y( :Y ),
	X(
		:Age, :Gender, :BMI, :BP, :Total Cholesterol, :LDL, :HDL, :TCH,
		:LTG, :Glucose
	),
	Validation( :Validation ),
	Minimum Splits Per Tree( 5 ),
	Portion Bootstrap( 1 ),
	Number Terms( 3 ),
	Number Trees( 25 ),
	Go
);
p_report = p << Report;
tb = p_report << XPath("//OutlineBox[text()='列贡献']//TableBox");

no work

2025-06-20_22-30-47.png

5 REPLIES 5
lala
Level IX

回复: How to copy the list of column contributions of a random forest using a script?

2025-06-20_22-36-37.png

jthi
Super User

Re: How to copy the list of column contributions of a random forest using a script?

Use Make Into Data table, take the source script from that and modify as needed

Names Default To Here(1);
rpt = New Window("Diabetes - Bootstrap Forest of Y",
	Data Table("Diabetes") << Bootstrap Forest(
		Y(:Y),
		X(
			:Age, :Gender, :BMI, :BP, :Total Cholesterol, :LDL, :HDL, :TCH, :LTG,
			:Glucose
		),
		Validation(:Validation),
		Method("Bootstrap Forest"),
		Column Contributions(1),
		Minimum Splits per Tree(5),
		Portion Bootstrap(1),
		Number Terms(3),
		Number Trees(25),
		Go
	)
);
Wait(0);
rpt["Bootstrap Forest for Y", "Column Contributions", Table Box(1)] <<
Make Into Data Table;
rpt << Close Window;
View more...
Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Diabetes.jmp");
bsf = dt << Bootstrap Forest(
	Y(:Y),
	X(:Age, :Gender, :BMI, :BP, :Total Cholesterol, :LDL, :HDL, :TCH, :LTG, :Glucose),
	Validation(:Validation),
	Minimum Splits Per Tree(5),
	Portion Bootstrap(1),
	Number Terms(3),
	Number Trees(25),
	Column Contributions(1),
	Go
);
Wait(0);


dt_res = Report(bsf)[Outline Box("Bootstrap Forest for ?"), Outline Box("Column Contributions"), Table Box(1)] << Make Into Data Table(Invisible);
m = dt_res[0, 0];
Close(dt_res, no save);

// could also 
m = Report(bsf)[Outline Box("Bootstrap Forest for ?"), Outline Box("Column Contributions"), Table Box(1)] << get;

If you just want the columns, you can build it from the resulting list or 

m = Report(bsf)[Outline Box("Bootstrap Forest for ?"), Outline Box("Column Contributions"), Table Box(1), StringColBox("Term")] << Copy Column;
-Jarmo
lala
Level IX

Re: How to copy the list of column contributions of a random forest using a script?

I still didn't succeed with my own actual data.

dt=Current Data Table();for(i=5,i<=ncol(dt),i++,if(Column(i)<<Get Name=="xx",Break()));ss=i+1;cNa=dt<<get column names;cNa=dt<<get column names;xF=As List(cNa[ss::ncol(dt)]);
rpt = New Window("Bootstrap Forest of Y",
dt << Bootstrap Forest(
	Y( Column( 3 ) ),
	X( Eval( xF ) ),
	Validation( :Validation ),
	Method( "Bootstrap Forest" ),
	Portion Bootstrap( 1 ),
	Number Terms( 46 ),
	Number Trees( 100 ),
	Go
));
Wait(0);rpt["Bootstrap Forest for Y", "Column Contributions", Table Box(1)] <<Make Into Data Table;

2025-06-21_16-23-00.png

lala
Level IX

Re: How to copy the list of column contributions of a random forest using a script?

I use the Chinese version of JMP, but it is feasible to run this code.

dt = Open( "$SAMPLE_DATA/Diabetes.jmp" );
cNa=dt<<get column names;xF=As List(cNa[3::ncol(dt)]);
rpt = New Window("Bootstrap Forest of Y",
	Data Table("Diabetes") << Bootstrap Forest(
		Y(1),
		X(Eval( xF )),
		Validation(:Validation),
		Method("Bootstrap Forest"),
		Column Contributions(1),
		Minimum Splits per Tree(5),
		Portion Bootstrap(1),
		Number Terms(3),
		Number Trees(25),
		Go
	)
);
Wait(0);
rpt["Bootstrap Forest for Y", "Column Contributions", Table Box(1)] <<Make Into Data Table;
jthi
Super User

Re: How to copy the list of column contributions of a random forest using a script?

Notice a difference between our scripts?

View more...
I'm using different outline box name than you are as I'm using wild card ? on purpose to replace the column name

You could possibly skip the first outline box reference and it should still work. 

-Jarmo

Recommended Articles