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.
Choose Language Hide Translation Bar
lala
Level VIII

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 VIII

回复: 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 VIII

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 VIII

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