0% found this document useful (0 votes)
10 views

Final

Uploaded by

Tisha Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Final

Uploaded by

Tisha Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

import pandas as pd

import matplotlib.pyplot as plt

# Load the data (ensure the CSV has a 'Week' column for proper
parsing)
df = pd.read_csv("C:/Users/Tisha/Downloads/input.csv")

# Group by 'Round' and 'Week' to sum the required columns over the 5
days of each week for each round
weekly_sum = df.groupby(['Round', 'Week'])[['total order', 'demand of
retailer1', 'demand of retailer2']].sum().reset_index()

# Group by 'Week' to sum the values from both rounds


week_sum = weekly_sum.groupby('Week')[['total order', 'demand of
retailer1', 'demand of retailer2']].sum().reset_index()

# Set the index to 'Week' for plotting


week_sum.set_index('Week', inplace=True)

# Create subplots
fig, axs = plt.subplots(3, 1, figsize=(12, 18))

# Plot Total Order


axs[0].plot(week_sum.index, week_sum['total order'], marker='o',
linestyle='-', color='blue', linewidth=2)
axs[0].set_title('Total Order by Week', fontsize=16)
axs[0].set_ylabel('Total Order', fontsize=14)
axs[0].grid(True, linestyle='--', alpha=0.7)

# Plot Demand of Retailer 1


axs[1].plot(week_sum.index, week_sum['demand of retailer1'],
marker='s', linestyle='-', color='orange', linewidth=2)
axs[1].set_title('Demand of Retailer 1 by Week', fontsize=16)
axs[1].set_ylabel('Demand of Retailer 1', fontsize=14)
axs[1].grid(True, linestyle='--', alpha=0.7)

# Plot Demand of Retailer 2


axs[2].plot(week_sum.index, week_sum['demand of retailer2'],
marker='^', linestyle='-', color='green', linewidth=2)
axs[2].set_title('Demand of Retailer 2 by Week', fontsize=16)
axs[2].set_ylabel('Demand of Retailer 2', fontsize=14)
axs[2].grid(True, linestyle='--', alpha=0.7)

# Add x-label for the bottom subplot


axs[2].set_xlabel('Week', fontsize=14)

# Adjust layout
plt.tight_layout()
plt.show()
# Define target variables for demand1, demand2, and total orders
target_retailer1 = week_sum['demand of retailer1']
target_retailer2 = week_sum['demand of retailer2']
target_total_orders = week_sum['total order']

from statsmodels.tsa.stattools import adfuller


# Define target variables in a dictionary
targets = {
'Retailer 1 Demand': target_retailer1,
'Retailer 2 Demand': target_retailer2,
'Total Orders': target_total_orders
}

# Loop through each target variable and perform the ADF test
for name, target in targets.items():
result = adfuller(target)
print(f'ADF Statistic for {name}: {result[0]}')
print(f'p-value for {name}: {result[1]}')

if result[1] < 0.05:


print(f"{name} is stationary, no differencing required (d=0)\
n")
else:
print(f"{name} is non-stationary, differencing required\n")
ADF Statistic for Retailer 1 Demand: -23.28378425677077
p-value for Retailer 1 Demand: 0.0
Retailer 1 Demand is stationary, no differencing required (d=0)

ADF Statistic for Retailer 2 Demand: -22.663477107633145


p-value for Retailer 2 Demand: 0.0
Retailer 2 Demand is stationary, no differencing required (d=0)

ADF Statistic for Total Orders: -21.601422151622316


p-value for Total Orders: 0.0
Total Orders is stationary, no differencing required (d=0)

# Step 3: Seasonal Decomposition to check for seasonality


decomposition = sm.tsa.seasonal_decompose(df['total order'],
model='additive', period=52) # Change period if needed
decomposition.plot()
plt.show()

# Step 3: Seasonal Decomposition to check for seasonality


decomposition = sm.tsa.seasonal_decompose(df['demand of retailer1'],
model='additive', period=52) # Change period if needed
decomposition.plot()
plt.show()

# Step 3: Seasonal Decomposition to check for seasonality


decomposition = sm.tsa.seasonal_decompose(df['demand of retailer2'],
model='additive', period=52) # Change period if needed
decomposition.plot()
plt.show()
import pmdarima as pm
import pandas as pd

# Step 2: Load your data


df = pd.read_csv("C:/Users/Tisha/Downloads/input.csv")

# Fit auto_arima while fixing d=0


model = pm.auto_arima(df['demand of retailer1'], d=0, start_p=0,
start_q=0,
max_p=5, max_q=5, seasonal=False, trace=True,
error_action='ignore', suppress_warnings=True)

# Print the best ARIMA order and AIC


print(f"Selected ARIMA order: {model.order}")
print(f"Model AIC: {model.aic()}")

Performing stepwise search to minimize aic


ARIMA(0,0,0)(0,0,0)[0] : AIC=447846.238, Time=0.17 sec
ARIMA(1,0,0)(0,0,0)[0] : AIC=inf, Time=0.22 sec
ARIMA(0,0,1)(0,0,0)[0] : AIC=402118.685, Time=1.43 sec
ARIMA(1,0,1)(0,0,0)[0] : AIC=286051.205, Time=0.33 sec
ARIMA(2,0,1)(0,0,0)[0] : AIC=285536.498, Time=2.97 sec
ARIMA(2,0,0)(0,0,0)[0] : AIC=inf, Time=0.28 sec
ARIMA(3,0,1)(0,0,0)[0] : AIC=285307.770, Time=7.47 sec
ARIMA(3,0,0)(0,0,0)[0] : AIC=inf, Time=0.37 sec
ARIMA(4,0,1)(0,0,0)[0] : AIC=284918.782, Time=8.09 sec
ARIMA(4,0,0)(0,0,0)[0] : AIC=inf, Time=0.44 sec
ARIMA(5,0,1)(0,0,0)[0] : AIC=283712.465, Time=8.09 sec
ARIMA(5,0,0)(0,0,0)[0] : AIC=inf, Time=0.72 sec
ARIMA(5,0,2)(0,0,0)[0] : AIC=inf, Time=15.76 sec
ARIMA(4,0,2)(0,0,0)[0] : AIC=inf, Time=18.86 sec
ARIMA(5,0,1)(0,0,0)[0] intercept : AIC=275992.928, Time=31.50 sec
ARIMA(4,0,1)(0,0,0)[0] intercept : AIC=280104.226, Time=19.68 sec
ARIMA(5,0,0)(0,0,0)[0] intercept : AIC=279202.615, Time=2.61 sec
ARIMA(5,0,2)(0,0,0)[0] intercept : AIC=inf, Time=30.32 sec
ARIMA(4,0,0)(0,0,0)[0] intercept : AIC=280270.819, Time=1.92 sec
ARIMA(4,0,2)(0,0,0)[0] intercept : AIC=inf, Time=24.76 sec

Best model: ARIMA(5,0,1)(0,0,0)[0] intercept


Total fit time: 175.995 seconds
Selected ARIMA order: (5, 0, 1)
Model AIC: 275992.9278466774

import pmdarima as pm
import pandas as pd

# Step 2: Load your data


df = pd.read_csv("C:/Users/Tisha/Downloads/input.csv")

# Fit auto_arima while fixing d=0


model = pm.auto_arima(df['demand of retailer2'], d=0, start_p=0,
start_q=0,
max_p=5, max_q=5, seasonal=False, trace=True,
error_action='ignore', suppress_warnings=True)

# Print the best ARIMA order and AIC


print(f"Selected ARIMA order: {model.order}")
print(f"Model AIC: {model.aic()}")

Performing stepwise search to minimize aic


ARIMA(0,0,0)(0,0,0)[0] : AIC=447648.671, Time=0.16 sec
ARIMA(1,0,0)(0,0,0)[0] : AIC=inf, Time=0.19 sec
ARIMA(0,0,1)(0,0,0)[0] : AIC=401945.322, Time=1.47 sec
ARIMA(1,0,1)(0,0,0)[0] : AIC=286663.201, Time=0.50 sec
ARIMA(2,0,1)(0,0,0)[0] : AIC=inf, Time=8.90 sec
ARIMA(1,0,2)(0,0,0)[0] : AIC=286664.582, Time=0.80 sec
ARIMA(0,0,2)(0,0,0)[0] : AIC=inf, Time=8.27 sec
ARIMA(2,0,0)(0,0,0)[0] : AIC=inf, Time=0.29 sec
ARIMA(2,0,2)(0,0,0)[0] : AIC=inf, Time=10.57 sec
ARIMA(1,0,1)(0,0,0)[0] intercept : AIC=282357.303, Time=5.60 sec
ARIMA(0,0,1)(0,0,0)[0] intercept : AIC=299217.741, Time=2.64 sec
ARIMA(1,0,0)(0,0,0)[0] intercept : AIC=282727.743, Time=0.89 sec
ARIMA(2,0,1)(0,0,0)[0] intercept : AIC=281415.847, Time=15.99 sec
ARIMA(2,0,0)(0,0,0)[0] intercept : AIC=282248.654, Time=1.24 sec
ARIMA(3,0,1)(0,0,0)[0] intercept : AIC=281124.276, Time=16.75 sec
ARIMA(3,0,0)(0,0,0)[0] intercept : AIC=281641.498, Time=1.62 sec
ARIMA(4,0,1)(0,0,0)[0] intercept : AIC=280674.617, Time=23.21 sec
ARIMA(4,0,0)(0,0,0)[0] intercept : AIC=280846.494, Time=1.82 sec
ARIMA(5,0,1)(0,0,0)[0] intercept : AIC=276592.958, Time=26.55 sec
ARIMA(5,0,0)(0,0,0)[0] intercept : AIC=279760.865, Time=2.41 sec
ARIMA(5,0,2)(0,0,0)[0] intercept : AIC=inf, Time=31.93 sec
ARIMA(4,0,2)(0,0,0)[0] intercept : AIC=inf, Time=27.74 sec
ARIMA(5,0,1)(0,0,0)[0] : AIC=284362.558, Time=8.90 sec

Best model: ARIMA(5,0,1)(0,0,0)[0] intercept


Total fit time: 198.442 seconds
Selected ARIMA order: (5, 0, 1)
Model AIC: 276592.95830631914

import pmdarima as pm
import pandas as pd

# Step 2: Load your data


df = pd.read_csv("C:/Users/Tisha/Downloads/input.csv")

# Fit auto_arima while fixing d=0


model = pm.auto_arima(df['total order'], d=0, start_p=0, start_q=0,
max_p=5, max_q=5, seasonal=False, trace=True,
error_action='ignore', suppress_warnings=True)

# Print the best ARIMA order and AIC


print(f"Selected ARIMA order: {model.order}")
print(f"Model AIC: {model.aic()}")

Performing stepwise search to minimize aic


ARIMA(0,0,0)(0,0,0)[0] : AIC=502611.463, Time=0.16 sec
ARIMA(1,0,0)(0,0,0)[0] : AIC=inf, Time=0.20 sec
ARIMA(0,0,1)(0,0,0)[0] : AIC=452613.367, Time=1.49 sec
ARIMA(1,0,1)(0,0,0)[0] : AIC=277446.101, Time=0.25 sec
ARIMA(2,0,1)(0,0,0)[0] : AIC=276909.832, Time=3.17 sec
ARIMA(2,0,0)(0,0,0)[0] : AIC=inf, Time=0.30 sec
ARIMA(3,0,1)(0,0,0)[0] : AIC=276733.492, Time=3.57 sec
ARIMA(3,0,0)(0,0,0)[0] : AIC=inf, Time=0.35 sec
ARIMA(4,0,1)(0,0,0)[0] : AIC=276325.169, Time=4.53 sec
ARIMA(4,0,0)(0,0,0)[0] : AIC=inf, Time=0.45 sec
ARIMA(5,0,1)(0,0,0)[0] : AIC=275183.672, Time=9.63 sec
ARIMA(5,0,0)(0,0,0)[0] : AIC=inf, Time=1.17 sec
ARIMA(5,0,2)(0,0,0)[0] : AIC=inf, Time=13.07 sec
ARIMA(4,0,2)(0,0,0)[0] : AIC=inf, Time=9.66 sec
ARIMA(5,0,1)(0,0,0)[0] intercept : AIC=268303.806, Time=27.48 sec
ARIMA(4,0,1)(0,0,0)[0] intercept : AIC=271334.758, Time=30.11 sec
ARIMA(5,0,0)(0,0,0)[0] intercept : AIC=270426.505, Time=2.53 sec
ARIMA(5,0,2)(0,0,0)[0] intercept : AIC=inf, Time=31.38 sec
ARIMA(4,0,0)(0,0,0)[0] intercept : AIC=271506.843, Time=1.86 sec
ARIMA(4,0,2)(0,0,0)[0] intercept : AIC=inf, Time=26.60 sec

Best model: ARIMA(5,0,1)(0,0,0)[0] intercept


Total fit time: 167.941 seconds
Selected ARIMA order: (5, 0, 1)
Model AIC: 268303.8063647584

You might also like