0% found this document useful (0 votes)
10 views3 pages

DS Exp7

The document outlines a procedure for performing polynomial regression using R. It includes steps for loading a dataset, fitting a quadratic model, making predictions, evaluating performance metrics (R², RMSE, MAE), and visualizing results with ggplot2. The result indicates successful execution of the polynomial regression on the dataset.

Uploaded by

LIGHTNING BOLT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

DS Exp7

The document outlines a procedure for performing polynomial regression using R. It includes steps for loading a dataset, fitting a quadratic model, making predictions, evaluating performance metrics (R², RMSE, MAE), and visualizing results with ggplot2. The result indicates successful execution of the polynomial regression on the dataset.

Uploaded by

LIGHTNING BOLT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EX NO :7

POLYNOMIAL REGRESSION
DATE:

AIM:
To develop r script using the above data set and fit polynomial regression.

ALGORITHM:

Step 1: Load the dataset → Read the CSV file containing battery usage vs. battery life.

Step 2: Fit a quadratic regression model → Use lm() with poly(Battery_Usage, 2, raw = TRUE).
Step 3: Make predictions → Use predict() to get fitted values.

Step 4: Evaluate model performance → Calculate R², RMSE, and MAE.


Step 5: Visualize results → Plot actual vs. predicted values using ggplot2.

CODE:
library(ggplot2)
data <- read.csv("your_dataset.csv")
colnames(data) <- c("Battery_Usage", "Battery_Life")
model <- lm(Battery_Life ~ poly(Battery_Usage, 2, raw = TRUE), data = data)
data$Predicted <- predict(model, newdata = data)
SSE <- sum((data$Battery_Life - data$Predicted)^2)
SST <- sum((data$Battery_Life - mean(data$Battery_Life))^2)
R2 <- 1 - (SSE/SST)
RMSE <- sqrt(mean((data$Battery_Life - data$Predicted)^2))
MAE <- mean(abs(data$Battery_Life - data$Predicted))
cat("R²:", R2, "\n")
cat("RMSE:", RMSE, "\n")
cat("MAE:", MAE, "\n")
ggplot(data, aes(x = Battery_Usage, y = Battery_Life)) +
geom_point(color = "blue", alpha = 0.6) +
geom_line(aes(y = Predicted), color = "red", size = 1) +

ARJUN SUDHEER -71812201021


labs(title = "Quadratic Regression: Battery Usage vs Battery Life",
x = "Battery Usage",
y = "Battery Life") +
theme_minimal()

OUTPUT:

ARJUN SUDHEER -71812201021


RESULT:
Thus, the polynomial regression has been done for the dataset successfully.

ARJUN SUDHEER -71812201021

You might also like