# Use Case of revenue prediction, featuring linear regression

Predicting the revenue from paid, organic, and social media traffic using a linear regression model in R.

We will now look at a real-life scenario where we will predict the revenue by using regression analysis in R. The sample dataset we will be working with is shown below:

In this demo, we will work with the following three attributes to predict the revenue:

1. Paid Traffic – Traffic coming through advertisement
2. Organic Traffic – Traffic from search engines, which is non-paid
3. Social Traffic     –  Traffic coming in from various social networking sites

We will be making use of multiple linear regression. The linear regression formula is:

Before we begin, let’s have a look at the program’s flow:

1. Generate inputs using csv files
2. Import the required libraries
3. Split the dataset into train and test
4. Apply the regression on paid traffic, organic traffic, and social traffic
5. Validate the model

So let’s start our step-by-step linear regression demo! Since we will perform linear regression in RStudio, we will open that first.

We type the following code in R:

Now, we move onto plotting the variables.

Let’s now see how the variables are correlated to each other. For that, we’ll take only the numeric column values.

As you can see from the above correlation matrix, the variables have a high degree of correlation between each other and with the sales variable.

Let’s now split the data from training and testing sets.

Now that we have the test and train variables, let’s go ahead and create the model:

The output of the above command is shown below in a graph that shows the predicted revenue.

Now let’s plot our test revenue with the following command:

Let’s go ahead and plot the prediction fully with the following command:

From the above output, we can see that the graphs of the predicted revenue and expected revenue are very close. Let’s check out the accuracy so we can validate the comparison.

The output looks like below:

You can see that this model’s accuracy is sound. This brings us to the end of the demo.