# Advertising Sales Prediction

What if you could predict sales of your product/service with the help of advertisements made on platforms like TV, Radio and newspaper?

The following project gives you a brief run through on how you can do that with the help of predictive analytics using certain machine learning and python packages and modules.

We start by importing the libraries and then we proceed with reading and exploring the dataset. To do that, the following line of codes were used, which is as follows: -

Over here we have imported pandas, scikit learn Linear regression and mean squared error modules. Pandas will help us to read, clean and explore the dataset followed by scikit learn linear regression and mean squared error model to prepare machine learning algorithms that will be used for prediction analysis.

We’ll now run the pandas command to read the csv file viz our dataset that’ll be used for predictive analytics: -

After running the command, we can now read and understand the data and what all is consisted in it.

Once this is done, it is always better to understand the data types of the columns in the dataset and what is their object type: -

Once the dataset has been understood the, it is time when the data needs to be cleaned, explored and wrangled for the final usage and to apply train and test runtime codes to it. To go ahead with that we’ll first identify and remove the duplicate values and then remove the null values from it, to proceed with that we use the .duplicated() and .isnull() command: -

Once this is done, the predictive analytics can take place after that with the help of scikit learn machine learning module within which we’ll apply Linear Regression models with it’s further subjective calculations for future forecasting of the data with the help of multiple statistical techniques and inferences by choosing the sales column in the dataset and by naming it as one of our factors after finding out the shape of the data. The chosen dales data column gets divided into two parts mainly for training the dataset and for testing the dataset, that helps us to further divide and get insights that’d then predict the data to show future prediction.

The dataset then needs to be understood with respect to its shape and structure, to do that we use the following command: -

We divide the training data into two variables as train_x and train_y with the first variable being the one that defines the first axis and the sales column of the dataset that is to be dropped and the main one to be used in the second variable.

The model is then chosen for analysis i.e., the Linear Regression model. The coefficient pattern is then chosen followed by the interception, prediction and the required mean squared error. The coefficient module helps in maintain coefficients of the values in the sales column of the dataset, followed by intercepting the values and then coming to the final stage to predict the necessary values. Once the data has been predicted, it is then trained to get the final results with the help of mean squared error module that derives the final calculations that is made to the values.

GitHub — https://github.com/advait27/advertising-prediction.git