# Machine Learning: Sales Prediction

Sales prediction with machine learning refers to the process of using machine learning algorithms and techniques to forecast future sales or revenue for a business or organization. It involves analyzing historical sales data, along with other relevant factors such as market trends, customer behavior, economic indicators, and promotional activities, to develop predictive models that can estimate future sales performance.

There are several reasons why sales prediction with machine learning is valuable:

1. Demanding forecasting
    
2. Budgeting and planning
    
3. Market Optimization
    
4. Inventory management
    
5. sales performance evaluation.
    

Machine learning techniques, such as regression, time series analysis, and ensemble methods, can be applied to sales data to build predictive models. These models can capture complex relationships between various factors influencing sales, providing businesses with valuable insights and accurate forecasts to support decision-making and strategic planning.

Steps for Project

**First, we need to install the libraries**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688111769877/d50e2ba4-a09a-4104-8825-0aadc1f43b1c.png align="center")

**Then, we need to load the dataset.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688111834762/648b623b-8391-4143-86ec-0bc3675e10be.png align="center")

**Now, doing data analysis**

First, we will find out that "describe" typically refers to a method or function that provides a summary or statistical description of a dataset

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688113394967/e69573ac-7027-4c16-9d32-267c6e996bbc.png align="center")

Then, we need to find out how many null values are there in the dataset

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688113478689/f67f4dfe-5b5b-4b03-8ebc-ffbb8754940b.png align="center")

For plotting the dataset, we will plot the heat map heat maps are used in various fields, including machine learning, to visualize and analyze data in a tabular format. They are particularly helpful when dealing with large datasets or matrices, as they provide a concise and intuitive representation of patterns, relationships, and distributions within the data

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115762938/109ef5ae-5155-4ee2-9b26-cbf6948c316e.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115782231/29cf3ec7-29fa-4ad1-a931-0318239b1873.png align="center")

**Then we will try to build the model for that first we will divide the dataset into X and y.**

X: All the columns except the Sales column.

y: Taking only the sales column.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115810810/219ab169-58e7-4e61-a35b-613d19726760.png align="center")

**Then for model building, we are using the Linear Regression.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115825568/5321538a-7ee8-4145-b988-c7de6791d3e5.png align="center")

**Dividing the dataset into the training and testing part for that we are using the train\_test\_split method.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115841748/2276e939-32a8-4956-b02b-56da1e6dde6e.png align="center")

**Now, building the model for that we are taking the model container and initiating the Model.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115855366/c0f1a2c3-c1ea-45c6-bda8-2d841d8eae69.png align="center")

**Fitting the model with the xtrain and ytrain.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115873327/98e1f61c-cb25-4b23-a1b4-73e4589648e9.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115884438/fc9cca0a-391a-4f45-9afd-a8d9b82b2403.png align="center")

**Here, is the output of the y prediction.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688115920786/18a677c1-8254-4389-96d3-2cf573a219ff.png align="center")
