You are on page 1of 2

EX NO: 8

AIM:

To Solve real-world problem using machine learning algorithm of Linear(Multiple)

ALGORITHM:

1. Load the Dataset:


 Load the mtcars dataset.
2. Build a Multiple Linear Regression Model:
 Use the lm function to create a multiple linear regression model
(model) with the following formula: mpg ~ wt + hp + qsec.
 mpg is the target variable (dependent variable).
 wt, hp, and qsec are the predictor variables (independent
variables).
 The data argument specifies that the data for the model should be
taken from the mtcars dataset.
3. Summarize the Model:
 Use the summary function to display a summary of the multiple linear
regression model. This summary includes:
 Coefficients: Provides information about the estimated
coefficients for each predictor variable ( wt, hp, qsec) and the
intercept.
 Model statistics: Includes R-squared, adjusted R-squared, F-
statistic, and p-values.
 Residuals: Provides information about the model's residuals,
such as mean, median, and quartiles.
4. Plot the Data:
 Create a scatter plot using the plot function.
 The x-axis represents the wt (weight) variable from the mtcars
dataset.
 The y-axis represents the mpg (miles per gallon) variable from
the mtcars dataset.
 Set the plot title to "Multiple Linear Regression Example" using
the main argument.
 Label the x-axis as "weight(wt)" using the xlab argument.
 Label the y-axis as "Miles per Gallon(mpg)" using the ylab
argument.
5. Add Regression Line:
 Use the abline function to add a regression line to the scatter plot.
 The model argument specifies that the regression line should
be based on the model created earlier.
 Set the color of the regression line to red using the col
argument.
PROGRAM:

data(mtcars)

model<-lm(mpg~wt+hp+qsec, data=mtcars)

summary(model)

plot(mtcars$wt,mtcars$mpg,main="Multiple Linear Regression


Example",xlab="weight(wt)",ylab="Miles per Gallon(mpg)")

abline(model, col="red")

OUTPUT:

Result :

Thus the above program is executed successfully.

You might also like