# scikit-learn: Predict Sales Revenue with Simple Linear Regression

In this project, you will build and evaluate a simple linear regression model using Python. You will employ the sklearn module for calculating the linear regression, while using pandas for data management, and seaborn for plotting. You will be working with the very popular advertising dataset to predict sales revenue based on advertising spending through mediums such as TV, radio, and newspaper.

By the end of this project, you will be able to: - Explain the core ideas of linear regression to technical and non-technical audiences - Build a simple linear regression model in Python with scikit-learn - Employ Exploratory Data Analysis (EDA) to small datasets with seaborn and pandas - Evaluate a simple linear regression model using appropriate metrics

Duration (mins)

Learners

#### 4.8 / 5

Rating

We will cover the following tasks in 45 minutes:

### Introduction and Overview

We will understand the Rhyme interface and our learning environment. You will be provided with a cloud desktop with Jupyter Notebooks and all the software you will need to complete the project. Jupyter Notebooks are very popular with Data Science and Machine Learning Engineers as one can write code in cells and use other cells for documentation.

We will also introduce the model we will be building as well the dataset for this Project.

In this task, we will load the very popular advertising dataset about various costs incurred on advertising by different mediums such as through TV, radio, newspaper, and the sales for a particular product. Next, we will briefly explore the data to get some basic information about what we are going to be working with.

### Removing the Index Column

Cleaning and preprocessing data is a vital process in data analysis and machine learning. In this task, we will take a look at our imported data and ascertain what to remove and what to keep for further analysis.

### Exploratory Data Analysis

It’s good practice to first visualize the data before doing any analysis and model building. If the data is high dimensional, at least examine few slices using simple techniques like box plots. In this task, we will look at the distributions of our response variable , Sales, and also looked at the distributions of our predictors, TV, Radio, and Newspaper.

### Relationship between Predictors and Response

Here we visualize pairwise correlations between our predictors and response. We also create a heatmap of the corresponding correlation matrix. This is done so as to ascertain whether there exists any relationship between the sales revenue and the expenditure on the various advertisement channels.

### Creating the Simple Linear Regression Model

Linear regression is an approach for modeling the relationship between a scalar dependent response variable y and one or more predictors (or independent variables) denoted X. The case where we have just one predictor is known as simple linear regression.

In this task, we are going to use the LinearRegression estimator from sklearn.model_selection to create our ordinary least squares (OLS) linear regression model. We will use train_test_split to split our data into training and test sets.

### Evaluation and Model Parameters

In this task we will use the intercept_ and summary() methods to produce human-readable output of our model coefficients and the OLS regression results.

### Making Predictions with the Model

Now that we have trained our OLS regression model on the training data, we will use predict() method to make predictions on the test data. Note that the predictions are made on data the model has never seen during train time.

### Model Evaluation Metrics

Evaluation metrics for classification problems, such as accuracy, are not useful regression problems. We need a metric designed to evaluate continuous values. In this task, we calculate and implement the three most common evaluation metrics for regression: Mean Absolute Error (MAE), Mean Squared Error (MSE), and Root Mean Squared Error (RMSE).

## Watch Preview

Preview the instructions that you will follow along in a hands-on session in your browser.

## Reviews

It's a very good idea to have both videos and the coding environment available at the same time, however with only one display to spare both the screens become pretty small, which is getting hard on the eye after some time.

sometimes i had difficulties with keyboard when used caps lock i can't switch back

Alexander Beloushkin

Potential Logistical Issues for Students On a large screen (I did it on a 17" Laptop) or with 2 screens it is fine to read both the notebook and the video. In this scenario using this platform would be more engaging than just watching a video (in my opinion). However, for those on mobile devices or using relatively small screens it may be a lot more practical to watch the videos and then do the notebook separately. It might also be prudent to ensure there is a sufficient time buffer beyond the predicted time to complete to minimize the potential of the cloud session timing out prior to the student finishing.

Ken Cotter

I would like to download the Jupitar file but, I could not.

Ahmed Tealeb

I hope the project will finally show up in Coursera as completed this time.

Alina-Oana Gârlea

Had a great learning experience with this platform. Hope there will be a lot of sessions that will be run in rhyme. kudos!

Robert Asturias

There are some typos, but overall it was a good experience. Is there a way for user to download the jupyter notebook to their own desktop?

Trunojoyo Anggara

I tried to think ahead. I was hoping the voice would motivate to do that more.

Marcel Wuijtenburg

Session too short, problem with [] for typing the code and screen too small (mac bookAir).

vignaux

## About the Host (Snehan Kekre)

Snehan Kekre is a Machine Learning and Data Science Instructor at Coursera. He studied Computer Science and Artificial Intelligence at Minerva Schools at KGI, based in San Francisco. His interests include AI safety, EdTech, and instructional design. He recognizes that building a deep, technical understanding of machine learning and AI among students and engineers is necessary in order to grow the AI safety community. This passion drives him to design hands-on, project-based machine learning courses on Rhyme.

##### How is this different from YouTube, PluralSight, Udemy, etc.?
In Rhyme, all projects are completely hands-on. You don't just passively watch someone else. You use the software directly while following the host's (Snehan Kekre) instructions. Using the software is the only way to achieve mastery. With the "Live Guide" option, you can ask for help and get immediate response.
##### Is this session really free?
Absolutely! Your host (Snehan Kekre) has provided this session completely free of cost!
##### Can I buy Rhyme sessions for my company or learning institution?
Absolutely. We offer Rhyme for workgroups as well larger departments and companies. Universities, academies, and bootcamps can also buy Rhyme for their settings. You can select projects and trainings that are mission critical for you and, as well, author your own that reflect your own needs and tech environments. Please email us at help@rhyme.com
##### What kind of accessibility options does Rhyme provide?
Rhyme strives to ensure that visual instructions are helpful for reading impairments. The Rhyme interface has features like resolution and zoom that will be helpful for visual impairments. And, we are currently developing a close-caption functionality to help with hearing impairments. Most of the accessibility options of the cloud desktop's operating system or the specific application can also be used in Rhyme. If you have questions related to accessibility, please email us at accessibility@rhyme.com
##### Why don't you just use containers or virtual browsers?
We started with windows and linux cloud desktops because they have the most flexibility in teaching any software (desktop or web). However, web applications like Salesforce can run directly through a virtual browser. And, others like Jupyter and RStudio can run on containers and be accessed by virtual browsers. We are currently working on such features where such web applications won't need to run through cloud desktops. But, the rest of the Rhyme learning, authoring, and monitoring interfaces will remain the same.
##### I have a different question
Please email us at help@rhyme.com and we'll respond to you within one business day.

## More Projects by Snehan Kekre

43 minutes
###### Classify Toxic Comments using Convolutions with Keras
1 hour and 11 minutes
42 minutes
57 minutes
52 minutes
41 minutes
52 minutes
###### Project: Facial Expression Recognition in Keras
1 hour and 24 minutes
###### Project: Real-Time Object Detection with YOLOv3
1 hour and 5 minutes
###### Project: Image Super Resolution using Autoencoders in Keras
1 hour and 4 minutes
53 minutes
###### scikit-learn: Logistic Regression for Sentiment Analysis
1 hour and 26 minutes
58 minutes
57 minutes
###### Predictive Analytics for Business with H2O and R
1 hour and 6 minutes
47 minutes
43 minutes
###### Create Interactive Dashboards with Streamlit and Python
1 hour and 33 minutes
50 minutes
53 minutes
###### Project: Regression Analysis with Yellowbrick
1 hour and 10 minutes
55 minutes
###### Project: Named Entity Recognition using LSTMs with Keras
1 hour and 10 minutes
47 minutes
###### Build a Machine Learning Web App with Streamlit and Python
1 hour and 21 minutes
###### Logistic Regression with NumPy and Python
1 hour and 3 minutes
47 minutes
58 minutes
###### Explainable Machine Learning with LIME and H2O in R
1 hour and 24 minutes
###### Automatic Machine Learning with H2O AutoML
1 hour and 1 minute
58 minutes
###### Build a Data Science Web App with Streamlit and Python
1 hour and 21 minutes
###### Project: Support Vector Machines with scikit-learn
1 hour and 40 minutes
48 minutes
52 minutes
52 minutes
###### Project: Predict Employee Turnover with scikit-learn
1 hour and 4 minutes
###### Project: Predictive Modelling with Azure Machine Learning Studio
1 hour and 6 minutes
###### Project: Anomaly Detection in Time Series Data with Keras
1 hour and 3 minutes
59 minutes
###### Project: Generate Synthetic Images with DCGANs in Keras
1 hour and 7 minutes
###### Project: Perform Feature Analysis with Yellowbrick
1 hour and 15 minutes
52 minutes