File size: 6,741 Bytes
e59e6e4
 
 
 
 
 
 
 
46acc58
e59e6e4
 
 
 
 
 
 
349b16b
 
46acc58
349b16b
 
 
 
3d06d5d
 
 
 
 
 
 
 
 
 
 
312261f
349b16b
c2d4beb
349b16b
 
 
 
 
 
 
 
312261f
3d06d5d
 
 
 
 
 
 
 
 
 
 
398831d
3d06d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f9426a4
3d06d5d
 
f9426a4
3d06d5d
f9426a4
3d06d5d
f9426a4
3d06d5d
f9426a4
3d06d5d
f9426a4
3d06d5d
f9426a4
3d06d5d
f9426a4
3d06d5d
f9426a4
3d06d5d
 
 
f9426a4
3d06d5d
8856ef2
436504d
 
 
 
 
 
 
 
 
 
3d06d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
b7defa5
3d06d5d
 
312261f
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# User Test Function (Prediction Script)

# Import required libraries
import pandas as pd
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import matplotlib.pyplot as plt
import pickle

import warnings
warnings.filterwarnings("ignore", category=UserWarning)

import streamlit as st
import os

st.title('Supply Chain Causal Analysis')

st.write("""Supply Chain Causal Analysis Model: 
            This TensorFlow-powered model utilizes advanced machine learning techniques to analyze and predict causal relationships 
            among key factors in a supply chain, including product demand, lead time, in stock count, pricing, advertising, weather, 
            and backorder status.            
            By uncovering these causal relationships, the model enables businesses to optimize their supply chain operations, reduce costs,
            and improve customer satisfaction. 
            Developed using TensorFlow, a powerful deep learning framework, this model offers accurate and efficient insights 
            into the complex dynamics of supply chain operations, empowering businesses to make data-driven decisions and drive 
            operational excellence""")

st.sidebar.header('Supply Chain Data')
# loading the save model
model = tf.keras.models.load_model(os.path.join('Weights_Updated','Best_model.tf'), compile=False) 

# loading the product label encoding object
with open ('le_product.pkl','rb') as file:
  le_product = pickle.load(file)

# loading the scaling object
with open ('scaler_scca.pkl','rb') as file1:
  scaler = pickle.load(file1)

# DATA from user
def user_report():
    # For Product
    Product = st.sidebar.selectbox("Product Name",("Product A", "Product B","Product C","Product D"))
    if Product=='Product A':
        Product=0
    elif Product=="Product B":
        Product=1
    elif Product=="Product C": 
        Product=2
    else:
        Product=3
    # For Lead_time
    Lead_time = st.sidebar.slider('Lead_time', 1,25,9)
    # For Demand
    Demand = st.sidebar.slider('Demand', 20,182,105)
    # For In_stock
    In_stock = st.sidebar.slider('In_stock', 20,250,219)
    # For Price
    Price = st.sidebar.slider('Price', 10,100,64)
    # For Advertising
    Advertising = st.sidebar.slider('Advertising', 1000,4500,2364)
    # For Weather
    Weather = st.sidebar.slider('Weather', 30,110,71)

    # Create a DataFrame for the input data
    user_report_data = {'Product': [Product],
                        'Lead_time': [Lead_time],
                        'Demand': [Demand],
                        'In_stock': [In_stock],
                        'Price': [Price],
                        'Advertising': [Advertising],
                        'Weather': [Weather]}

    # # encoded the Product using loaded product label encoder object
    # le_product_encoded = le_product.transform([Product])[0]
    
    # # scaling the input_data using loaded scaler object
    # report_data = scaler.transform(input_data)

    report_data = pd.DataFrame(user_report_data, index=[0])
    return report_data 

    
# Supply Chain Data Details
user_data = user_report()
st.subheader("Supply Chain Data Details")
st.write(user_data)

# User_function 
def predict_backordered(user_data):

    df = pd.read_csv('Supply_chain_causal_analysis_Synthetic_Dataset_Final.csv')

    # # encoded the Product using loaded product label encoder object
    # Product = le_product.transform([Product])[0]

    # scaling the input_data using loaded scaler object
    user_data = scaler.transform(user_data)
    
    # Make predictions using the pre-trained TensorFlow model
    predictions = model.predict(user_data)
    if predictions == 1:
      return "Backorders are likely to occur."
    else:
      return "Backorders are unlikely to occur."

# Function calling
y_pred = predict_backordered(user_data)
if st.button("Predict"):
    st.subheader(y_pred)


st.write("""Features Used:

The following are the input Varibles from the End user which needs to be enter, and then the application will predict whether 
the particular Product has the chances of having Backorder or not.

1: Product: Name of the product.

2: Lead_time: The average number of days taken to deliver the product after placing the order.

3: Demand: The number of units of the product demanded during a specific time period.

4: In_stock: The number of units of the product currently available in the inventory.

5: Price: The selling price of the product.

6: Advertising: The amount spent on advertising the product during a specific time period.

7: Weather: Weather condition during a specific time period that could affect the demand for the product.

In a retail scenario, weather could be measured in terms of temperature in Fahrenheit or Celsius,
and since temperature affects the demand for products such as clothing, food, and beverages. It is also one of the important factor
to be considered for causal analysis of Supply chain management.

Target Column/Prediction: 
Backordered: A binary variable indicating whether the product will be backordered (1) or not (0) during a specific 
             time period. This is the target variable that we want to predict

Backorder refers to a situation where a requested item is not immediately available due to insufficient inventory or other factors. 
It can impact customer satisfaction, result in delayed deliveries, and potentially lead to revenue loss. Businesses need to manage 
backorders effectively by monitoring inventory levels, optimizing supply chain processes, and providing timely updates to customers. 
Backorders can also be used strategically as a marketing tactic, but must be handled carefully to avoid customer disappointment and 
maintain a positive reputation.

In short, Backorder is one of the most important factor in terms of supply chain which means when a particular order goes of out of 
stock and demand comes for that out of stock product.""")




# # user_data = user_report()
# # st.subheader("Component Details")
# # st.write(user_data)

# # Function calling
# y_pred = prediction(user_data)
# st.write("Click here to see the Predictions")
# if st.button("Predict"):
#     st.subheader(f"Next Failure is {y_pred} hours ")

# Test these data
# Product D, 9.0, 105.0, 219.0, 64.0, 2364.0, 71.24 - for this 0 (Backorders are unlikely to occur)
# #predict_backordered('Product C', 5.0, 105.0, 177.0, 38.0, 1598.0, 83.31) - for this 1 (Backorders are likely to occur)