Skip to content
CampusEduX

Problem 4: Calculate R² for a Trained Regression Model

Easypython
Learn the Concept: Regression Metrics (MAE, MSE, RMSE, R²)

Problem Description

Write a Python program that trains a Linear Regression model, generates predictions on a test set, and calculates the R² score to evaluate model fit.

Input

Training data and a separate test set.

Output

The R² score on the test set.

Constraints

  • At least 5 data points in each set.

Example Input

text
(A Linear Regression model trained on 5 points, tested on 3 new points)

Example Output

text
R² Score: 0.91

Concepts Covered

LinearRegression, r2_score(), train-test evaluation.

Related Problems

  • Problem 1: Calculate All Four Regression Metrics
    Easy · python
    Solve Problem
  • Problem 2: Manually Calculate MAE and MSE
    Easy · python
    Solve Problem
  • Problem 3: Compare MAE and RMSE with an Outlier
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...