Choose Language Hide Translation Bar
Highlighted
giaMSU
Level II

Extract R2 in multiple reports and save in a .txt or .CSV file

Hi, 

I've run a script that automates multiple Neural Network (NN) analyses. In each run, the script saves an NN report as a PDF file, including R^2 values of Training and Validation. It becomes an issue since I, finally, have around 1000 PDF files. 

Please see the script below

dt = Open( "E:/Subset of9Year.jmp" )
Summarize( locs = BY(dt:ID) );
//To create a subset of each ID for Neural Input
For(
	j=1, j<=NItems(locs), j++,
	file = dt << Select Where(locs[j] == Char (:ID)) << Subset(
		file,
		Output Table Name("Model Subset File")
	);
//Run Neural Network with 2 layers with 6/3 nodes
	NN = file << Neural(
	Y( :Name( "SoilMoisture(kg.m-2) or (mm)" ) ),
	X(
		:Name( "Tmax(K)" ),
		:Name( "Tmin(K)" ),
		:Name( "Precip(mm)" ),
	),
	Informative Missing( 0 ),
	Transform Covariates( 1 ),
	Validation Method( "KFold", 7 ),
	Set Random Seed( 1234 ),
	Fit(
		NTanH( 1 ),
		NLinear( 1 ),
		NGaussian( 1 ),
		NTanH2( 3 ),
		NGaussian2( 3 ),
		Transform Covariates( 1 ),
		Robust Fit( 1 ),
		Penalty Method( "Absolute" ),
		Number of Tours( 10 ),
		//Show Estimates( 1 ),  //show estimates
		//Diagram( 1 ),
		//Plot Actual by Predicted( 1 ), // print plot obj vs predicted
		Save Formulas,
		//Get RSquare Test //Get RSquare Validation 
	)
);
	//Read and save each report as a PDF file
NNReport = NN << Report; NNReport << Save PDF("E:/result/model_"|| Char (j)||".pdf"); );

Is there a method to extract R2 in multiple reports and save them in a file?

Thank you in advance. Any suggestion is welcome. 

 

 

3 REPLIES 3
Highlighted
txnelson
Super User

Re: Extract R2 in multiple reports and save in a .txt or .CSV file

Using JMP's ability to parse out any item within the Display output, through the Display Trees, you can grab any of the output you want.  Here is a simple example of getting the Validation RSquare from a Neural output

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );
obj = Neural(
	Y( :mvalue ),
	X( :crim, :indus, :chas, :nox, :rooms, :age, :distance, :radial ),
	Go
);
rSquare = (report(obj)["Validation"]["mvalue"][NumberColBox(1)]<<get)[1];

Documentation on Display Trees can be found in the Scripting Guide

     Help=>JMP Documentation Library

then look in the Scripting Guide 

Jim
Highlighted
giaMSU
Level II

Re: Extract R2 in multiple reports and save in a .txt or .CSV file

I try to save rSquare value by using Save text. However, it cannot create a text file.

As I understand (maybe wrong), the  script get rSquare value and save it somewhere in JMP. Then I used Save Text to save the value to a .txt file. 

JMP error message is " rSquare << /*###*/Save Text( "D:/GYST_ERIK/pdm.txt" ) /*###*/;
{}"

Can you help me, please?

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );
obj = Neural(
	Y( :mvalue ),
	X( :crim, :indus, :chas, :nox, :rooms, :age, :distance, :radial ),
	Go
);
rSquare = (report(obj)["Validation"]["mvalue"][NumberColBox(1)]<<get)[1];
show (rSquare);
rSquare << Save ("D:/GYST_ERIK/pmd.txt");

 

Highlighted
txnelson
Super User

Re: Extract R2 in multiple reports and save in a .txt or .CSV file

The function you want to use is

     Save Text File()

Look in the Script Editor and it has an example and additional options that can be used.

 

Since your variable is a string, you can use

Save Text File("D:/GYST_ERIK/pmd.txt", rSquare);

or maybe

Save Text File("D:/GYST_ERIK/pmd.txt", "Boston Results " || rSquare);
Jim
Article Labels

    There are no labels assigned to this post.