-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsales.prediction.py
More file actions
42 lines (31 loc) · 1.04 KB
/
Copy pathsales.prediction.py
File metadata and controls
42 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
# Load dataset
data = pd.read_csv("sales_data.csv")
# Convert Date column to datetime
data['Date'] = pd.to_datetime(data['Date'])
# Convert date to numerical value (number of days)
data['Days'] = (data['Date'] - data['Date'].min()).dt.days
# Input (X) and Output (y)
X = data[['Days']]
y = data['Sales']
# Create model
model = LinearRegression()
# Train model
model.fit(X, y)
# Predict future sales (next 5 days)
future_days = np.array([16,17,18,19,20]).reshape(-1,1)
predicted_sales = model.predict(future_days)
print("Predicted Sales for Next 5 Days:")
for i, sale in enumerate(predicted_sales):
print("Day", future_days[i][0], ":", int(sale))
# Plot graph
plt.scatter(data['Days'], data['Sales'], color='blue', label='Actual Sales')
plt.plot(data['Days'], model.predict(X), color='red', label='Regression Line')
plt.xlabel("Days")
plt.ylabel("Sales")
plt.title("Sales Forecasting using Machine Learning")
plt.legend()
plt.show()