Choose Language Hide Translation Bar
Highlighted
MAS
MAS
Level III

Re: Generalized Regression--retrieve tuning parameter script

Thanks for the quick response, Clay. Much appreciated.

 

The issue I'm having now is that I don't know how to control penalty parameter for each iteration. In a previous script, you had this: 

penaltyVector = fm << (fit[1] << get penalty grid);

I'm also not getting a new JMP table with the results. 

Just for the purpose of double-checking, would it be possible to add as the first row in the output table the value of the penalty parameter from that particular iteraction? 

Highlighted

Re: Generalized Regression--retrieve tuning parameter script

Would it work to put the lambda value in the name of the prediction formula?

If so, you could do something like below. The script matches up the penalty values the we get from <<get penalty grid with the associated column of predicted values.

 

dt = Open( "$SAMPLE_DATA/Diabetes.jmp" );

fm = Fit Model(
	Y( :Y ),
	Effects( :BMI, :BP, :Total Cholesterol, :LDL, :HDL ),
	Personality( "Generalized Regression" ),
	Generalized Distribution( "Normal" ),
	Run( Fit( Estimation Method( Lasso ), Validation Method( AICc ) ) )
);

lambdas = fm << (Fit[1] << get penalty grid);


// loop through each solution and save the predictions
for(i=0, i<150, i++,      // the first solution is solution 0
	fm << (Fit[1] << set solution ID(i));
	fm << (Fit[1] << save prediction formula);
	newc =column(dt, ncol(dt));
	newc << set name( newc<<get name || "(lambda=" || char(round(lambdas[i+1], 2)) || ")");
);

 

 

 

 

 

Highlighted
MAS
MAS
Level III

Re: Generalized Regression--retrieve tuning parameter script

Ah, I see where you're going with this. But I need the numerical value of the lambda in the data table so that I can use it in a subsequent graph. Would it be possible to create a new output table with the lambdas in the first row and predictions in subsequent rows?

Highlighted

Re: Generalized Regression--retrieve tuning parameter script

Something like this? The penalties are in the first row and the predictions are in the following rows.

 

dt = Open( "$SAMPLE_DATA/Diabetes.jmp" );

fm = Fit Model(
	Y( :Y ),
	Effects( :BMI, :BP, :Total Cholesterol, :LDL, :HDL ),
	Personality( "Generalized Regression" ),
	Generalized Distribution( "Normal" ),
	Run( Fit( Estimation Method( Lasso ), Validation Method( AICc ) ) )
);

lambdas = fm << (Fit[1] << get penalty grid);
lambdas = lambdas`;
nGridPoints = ncol(lambdas);

// loop through each solution and save the predictions
for(i=0, i<nGridPoints, i++,      // the first solution is solution 0
	fm << (Fit[1] << set solution ID(i));
	fm << (Fit[1] << save prediction formula);
);

ncols = ncol(dt);
predictions = dt[0,(ncols-nGridPoints+1)::ncols];
newTable = as table(lambdas |/ predictions);
newTable<<setName("Penalties and Predictions");
Highlighted
MAS
MAS
Level III

Re: Generalized Regression--retrieve tuning parameter script

Excellent! Thank you, Clay...

Article Labels

    There are no labels assigned to this post.