1.1.5 Predicting
predict evaluates a fit on predictor rows in the same column order as X. For a Gaussian model it returns the fitted response values. Here we use the first three cars to demonstrate prediction:
> (define prediction-X (design-matrix-select-rows X '(0 1 2))) > (predict fit prediction-X) '(23.57233251122761 22.583482531387332 25.2758235591189)
These rows were also used for fitting, so the predictions are fitted values, not a test of performance on unseen data. To predict new observations, prepare their weight and horsepower in the same units as the training data and in the same column order, and pass them to predict.
For the formula model, supply a table of predictors. Their names determine which coefficients apply, so column order does not matter and the response column is unnecessary:
> (define prediction-data (polars->table (pl:head cars 3) (reverse feature-names))) > (predict named-fit prediction-data) '(23.57233251122761 22.583482531387332 25.2758235591189)
A classifier also accepts #:type to choose its linear predictor, probabilities ('response), or classes ('class); see Predictions and coefficients. A path predicts at selected values of λ, including values between those it fitted.