Skip to main content Link Search Menu Expand Document (external link)

Procedure 8: Using the predict function for a one way linear regression one

Deploying a linear regression model manually is rather simple, however, there is an even simpler method available in calling the predict() function which takes a model and a data frame as its parameter, returning a prediction vector.

AutomaticLinearRegression <- predict.lm(LinearRegression,FDX)

img.png

Run the line of script to console:

img_1.png

Add the newly created vector to the FDX data frame:

FDX <- mutate(FDX, AutomaticlLinearRegression)

img_2.png

Run the line of script to console:

img_3.png

To view the last two columns of the data frame, containing a manually derived prediction and automatically derived prediction:

View(FDX[,203:204])

img_4.png

Run the line of script to console:

img_5.png

The manual and automatic prediction shown side by side are identical to each other. It follows that the automatic prediction is a much more concise means to execute the prediction based upon a linear regression model created in R:

img_6.png


Jube™. © Jube Holdings Limited 2022 to present.