You are on page 1of 5

EXPERIMENT 1.

3
Name: Vishal Chauhan UID: 20BCS1725
Section/Group 20BCS-37-B Course: Business Intelligence Lab

Aim:
Write a program to implement Sales Revenue Prediction using Linear Regression

Software Required:

Jupyter Notebook Description:


The objective of this experiment is to implement a linear regression model to predict sales
revenue based on historical data. By writing a program to implement linear regression, we aim
to understand the relationship between independent variables (e.g., advertising expenditure,
market size) and sales revenue, and develop a prediction model for future sales revenue.

Pseudo code/Algorithms/Flowchart/Steps:
import numpy as np import
pandas as pd import matplotlib.pyplot
as plt
import seaborn as sns import
mpl_toolkits
from sklearn import linear_model %matplotlib inline
plt.style.use('ggplot') import warnings
warnings.filterwarnings("ignore") data =
{'Marketing Budget (X) in Thousands' :
[127.4,364.4,150,128.7,285.9,200,303.3,315.7,169.8,104.9,297.7,256.4,249.1,323.1,223,23
5,200]
,'Actual Sales(Y) in Millions' :
[10.5,21.4,10,9.6,17.4,12.5,20,21,14.7,10.1,21.5,16.6,17.1,20.7,15.5,13.5,12.5]}

df = pd.DataFrame(data, columns = ['Marketing Budget (X) in Thousands','Actual Sales(Y)


in Millions'])

# Visualizing the data using heatmap sns.heatmap(df.corr(), cmap="YlGnBu",


annot = True) plt.show()

plt.figure(figsize=(12,6)) plt.scatter(df['Marketing Budget (X) in Thousands'],


df['Actual Sales(Y) in Millions'],
color='red') plt.title('Sales Vs Budget',
fontsize=14)
plt.xlabel('Marketing Budget (k)', fontsize=14) plt.ylabel('Actual
Sales (m)', fontsize=14) plt.grid(True)
plt.show()

n_df = df.drop('Actual Sales(Y) in Millions',axis='columns') n_df

sales = df['Actual Sales(Y) in Millions'] sales

# Create linear regression object lr = linear_model.LinearRegression()


lr.fit(n_df,sales)

#let's predict Sales for a given budget amount lr.predict([[150]])

#let's generate model prediction for all budget amounts in our dataset y_predict =
lr.predict(n_df)

# Visualize the predicted amount as a line on the test set


#The scatter-plot with best-fit line looks like plt.figure(figsize=(12,6))
plt.scatter(df['Marketing Budget (X) in Thousands'], df['Actual
Sales(Y) in Millions']) plt.plot(df['Marketing Budget (X) in
Thousands'], y_predict, 'r') plt.show()

#Generate a file with list of sales predictions


# Intercept value print("Intercept
:",lr.intercept_)

# Slope value
print('Slope :',lr.coef_)
# Manually plotting the line with above Intercept and Slope plt.figure(figsize=(12,6))
plt.scatter(df['Marketing Budget (X) in Thousands'], df['Actual Sales(Y) in Millions'])
plt.plot(df['Marketing Budget (X) in Thousands'], 0.05276727*df['Marketing Budget (X) in
Thousands'] + 3.3524968264935975, 'r') plt.show()

plt.figure(figsize=(12,6)) x_ax =
range(len(df['Actual Sales(Y) in Millions']))
plt.plot(x_ax, df['Actual Sales(Y) in Millions'], label="original")
plt.plot(x_ax,y_predict, label="predicted") plt.title("Actual Sales and
predicted data") plt.legend()
plt.show()

Output:

You might also like