Machine Learning: Future Sales Prediction
Predicting the future sales of a product helps a business manage the manufacturing and advertising costs of the product. There are many more benefits of predicting the future sales of a product. So if you want to learn to predict the future sales of a product with machine learning, let's code step by step.
First, we need to understand the dataset. In the dataset, you can see that there are
TV: Advertising cost spent in dollars for advertising on TV;
Radio: Advertising cost spent in dollars for advertising on Radio;
Newspaper: Advertising cost spent in dollars for advertising on Newspaper;
Sales: Number of units sold.
First, we need to import the libraries.

Then, we need to load the dataset using the pandas which is from the read_csv.

Using the head command which will give you the five top rows and columns

getting the bottom five through the tail() command

getting the more information which gives the in-depth information about the dataset

The describe method is used to generate descriptive statistics of a data frame which includes numeric columns, including count, mean, standard deviation, minimum and maximum.

Now, the isnull() method will give the details about each row and column which is to check for missing or null values in a DataFrame.
d-types will provide you the information about the data type of each column, helping you understand how your data is stored.

Now, plot the graph using the plotly. express.
first plot the graph for the sales and tv using the px scatter plot.


scatter plot for the dataset between the sales and Newspaper

scatter plot the graph between the sales and radio

now, finding the correlation for the dataset which gives correlation of the dataset.

Now, spliting the dataset into the X and y in which the X includes all the columns except the sales column and y column includes only the sales.

now, importing the necessary libraries for the further step which is train_test_split and the Linear regression from the sklearn model.

Now, with the help of the train_test_split we are doing the x_train, x_test, y_train, y_test. taking the values of X, y, the test_size and the random_state.

Finally, the most important step of all building the model using the Linear regression. Then fitting the module using the X_train and the y_train.

getting the score of the model in that we are taking the values of the x_test and the y_test.

Finally we take the new values for the prediction we then take the features and then make the model to predict the features using the machine learning algorithm.

Thanks for reading,
Mohammed Muqafamuddin.
Comments
Join the discussionNo comments yet. Be the first to comment.