Evan Aad
Evan Aad

Reputation: 6035

How to apply the results of linear regression on a training set of data to a testing set of data?

I have two non-empty dataframes: training and testing. Each of these dataframes has two columns: Y and X, in this order. I have applied linear regression analysis to training as follows:

m <- lm(Y ~ X, data = training)

I would like to apply the coefficients resulting from this fitting to the data in testing to obtain the same types of information available in the object m for purposes of further analysis and data visualization. How can I do this?

Upvotes: 2

Views: 3867

Answers (1)

user1808924
user1808924

Reputation: 4926

See the predict.lm function:

Y_pred = predict(m, newdata = testing)

Upvotes: 2

Related Questions