This document describes using a multiple linear regression algorithm to solve a real-world problem. It loads automobile data, builds a regression model to predict miles per gallon based on weight, horsepower, and quarter mile time, summarizes the model, plots the data with a regression line, and confirms the program executed successfully.
This document describes using a multiple linear regression algorithm to solve a real-world problem. It loads automobile data, builds a regression model to predict miles per gallon based on weight, horsepower, and quarter mile time, summarizes the model, plots the data with a regression line, and confirms the program executed successfully.
This document describes using a multiple linear regression algorithm to solve a real-world problem. It loads automobile data, builds a regression model to predict miles per gallon based on weight, horsepower, and quarter mile time, summarizes the model, plots the data with a regression line, and confirms the program executed successfully.
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)")