Menu

Predictive Modeling with R: Linear Regression and Model Evaluation

Predictive Modeling with R

Introduction to Linear Regression

Linear regression draws the best straight line through your data, so you can predict one number from others. You write it using lm(), with the target on the left and the inputs on the right.

Read three things in the result:

  • Coefficients: Show the estimated relationship between each input and the target.
  • p-values: Help assess whether the estimated relationships provide evidence against a null hypothesis.
  • R-squared: Shows how much of the variation in marks the model explains.

A simple model with two inputs is often easier to explain than a complex one, and it can work just as well.

Building a Simple Student Performance Prediction Model

To build a fair model, split the data into two parts. Use 80 percent to train the model and keep 20 percent as a test set that the model has never seen.

Train on the first part, then predict on the second. This shows how the model would work on new students. Set a seed before you split, so your training and test sets stay the same each time you run the code.

The full code is in the project at the end of this level.

Evaluating Model Performance

Judge a model on the test data, not the training data. Use three numbers:

  • RMSE (Root Mean Squared Error): Measures prediction error, giving larger errors more weight.
  • MAE (Mean Absolute Error): Measures the average absolute prediction error.
  • R-squared: Shows how much of the variation the model explains.

If a model scores well on training data but badly on test data, it has learned the training data too closely. This problem is called overfitting.

Compare your errors with the scale of the marks. An error of four marks on a 100-mark scale may be small, depending on the context.


R for Data Science

HA

Harini A



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details