0% found this document useful (0 votes)
12 views5 pages

Code For Linear Regression Analysis

The document outlines practice problems for linear regression analysis, including steps for importing libraries, preparing data, splitting datasets, training models, making predictions, visualizing results, and evaluating model performance using Mean Absolute Error (MAE). It also includes a multiple linear regression problem focused on predicting sales based on advertisement across different media channels. The document emphasizes the importance of interpreting model coefficients to understand the contribution of each advertising medium to sales.

Uploaded by

likith9380
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)
12 views5 pages

Code For Linear Regression Analysis

The document outlines practice problems for linear regression analysis, including steps for importing libraries, preparing data, splitting datasets, training models, making predictions, visualizing results, and evaluating model performance using Mean Absolute Error (MAE). It also includes a multiple linear regression problem focused on predicting sales based on advertisement across different media channels. The document emphasizes the importance of interpreting model coefficients to understand the contribution of each advertising medium to sales.

Uploaded by

likith9380
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/ 5

Linear Regression: Practice Problems

Problem-1: Consider a small sample of the dataset as shown below and perform linear regression analysis.

Solution:

1. Importing Libraries:
Import the necessary libraries. You will be using pandas for data manipulation and sklearn for building the
linear regression model.

2. Preparing the Data:


Load your data into a DataFrame and split it into features (X) and target variable (y).
3. Splitting the Data:
Split the data into training and testing sets to evaluate the model’s performance.

4. Training the Model:


Now, fit a simple linear regression model to the training data used.

5. Making Predictions:
Use the model to predict the test scores for the test data.

6. Visualizing the Results:


Visualize the training data along with the regression line.

7. Evaluating the Model:


Check the model’s performance using metrics such as Mean Absolute Error (MAE).
Problem-2: Consider the data set given below and predict the house prices based on their square footage.

Multiple Linear Regression Practice Problem


Problem-1: Consider the data shown below, which is commonly used in marketing analytics and predict the sales
based on advertisement across different media channels - TV, radio, and newspaper.

Solution:

1. Importing Libraries:
2. Preparing the Data:
Load the data into a DataFrame and separate the features and target variable.

3. Splitting the Data:


Split the data into training and testing sets.

4. Training the Model:


Fit a multiple linear regression model to the training data.

5. Making Predictions:
Use the model to predict sales for the test data.
6. Evaluating the Model:

Evaluate the model’s performance using Mean Absolute Error (MAE).

7. Interpreting the Results:

The coefficients of the model will tell us how much each advertising medium contributes to sales. We can
get the details using the function as follows:

*****

You might also like