We can use the predict()
function for a number of purposes. For instance,
we can obtain the ridge regression coefficients for a new value of
> predict(ridge.mod, s = 50, type = "coefficients")[1:20,] (Intercept) AtBat Hits HmRun 4.876610e+01 -3.580999e-01 1.969359e+00 -1.278248e+00 Runs RBI Walks Years 1.145892e+00 8.038292e-01 2.716186e+00 -6.218319e+00 CAtBat CHits CHmRun CRuns 5.447837e-03 1.064895e-01 6.244860e-01 2.214985e-01 CRBI CWalks LeagueN DivisionW 2.186914e-01 -1.500245e-01 4.592589e+01 -1.182011e+02 PutOuts Assists Errors NewLeagueN 2.502322e-01 1.215665e-01 -3.278600e+00 -9.496680e+00
Try predicting the coefficients for
Assume that:
ISLR2
and glmnet
libraries have been loadedHitters
dataset has been loaded and attached