dt = Open( "$SAMPLE_DATA/Liver Cancer.jmp" );
fd = Formula Depot(); // open a new Formula Depot
obj1 = dt << Run Script( "Lasso Poisson, Validation Column" );
model = obj1 << (Fit[1] << Publish Prediction Formula); /* add a formula. The following more complex script opens a formula depot report, adds a model to the depot, generates scoring code for the formula, saves the code to a file, and closes all windows.*/
case_name = "fitLS_prediction";
dest_dir = "c:\";  //CHANGE ME to a better location
 
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Print( "Running " || case_name );
fm_ls = Fit Model(
	Y( :weight ),
	Effects( :age, :sex, :height ),
	Personality( Standard Least Squares ),
	Emphasis( "Minimal Report" ),
	Run
);
fd = fm_ls << Publish Prediction Formula;
 
Try(
	Print( "Generate Python Code" );
	fd << Generate Python Code();
	Wait( 1 );
	cw = Window( "Python Code Output" );
	ed = cw[Script Box( 1 )];
	code = ed << Get Text;
	Save Text File( dest_dir || case_name || ".py", code );
	cw << Close Window( No Save );
	Print( "Done." );
,
	Print( "Code generation failed for " || case_name || ", reason: " );
	Show( exception_msg );
);
fdw = Window( "Report: Formula Depot" );
fdw << Close Window( No Save );
Close( dt, No Save );

Help created on 9/19/2017