Coders Packet

Sales Prediction using Python

By Bommala Shreya

Sales prediction is a focuses on predicting the future direction of sales. It involves analyzing historical data, market trends, and various indicators to make predictions .

Sales Prediction using Python

About:

Sales prediction is the process of using historical data and various factors to forecast future sales performance. It's a crucial task for businesses to make informed decisions about inventory management, marketing strategies, and resource allocation.

Algorithm:

The theoretical concept involves:
- Data Collection: Gather historical sales data and relevant features like time, promotions, weather, etc.
- Data Analysis: Explore and visualize the data to identify patterns, trends, and relationships.
-Feature Selection: Choose important features that could impact sales predictions.
- Model Selection: Decide on a suitable prediction model, such as Linear Regression, Decision Trees, or more advanced ones like Neural Networks.
- Training: Train the chosen model on the historical data to learn the relationships between features and sales.
- Evaluation: Use metrics like Mean Squared Error or Root Mean Squared Error to assess how well the model predicts on new data.
- Prediction: Apply the trained model to new data to make sales forecasts.

Keep in mind that the success of sales prediction depends on the quality of data, the appropriateness of the chosen model, and the accuracy of feature selection. It's an iterative process that often involves refining the model and updating it as new data becomes available.

Program Code:

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Load the Advertising dataset from CSV
advertising_data = pd.read_csv('/content/Advertising salesprediction oasis dataset.csv')

# Split the dataset into features (X) and target (y)
X = advertising_data[['TV', 'Radio', 'Newspaper']]
y = advertising_data['Sales']

# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create and train the linear regression model
model = LinearRegression()
model.fit(X_train, y_train)

# Make predictions on the test set
y_pred = model.predict(X_test)

# Calculate the root mean squared error (RMSE)
rmse = mean_squared_error(y_test, y_pred, squared=False)
print("RMSE:", rmse)


import matplotlib.pyplot as plt
import seaborn as sns

# Visualize the relationship between the features and the target variable
sns.pairplot(advertising_data, x_vars=['TV', 'Radio', 'Newspaper'], y_vars='Sales', height=4, aspect=1, kind='scatter')
plt.show()

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Bommala Shreya (bommalashreya09)

Download packets of source code on Coders Packet