animay620 commited on
Commit
36a9a24
1 Parent(s): f77f5cd

Upload 7 files

Browse files
Files changed (8) hide show
  1. .gitattributes +1 -0
  2. Sales forecasting.ipynb +0 -0
  3. app.py +110 -0
  4. features.csv +0 -0
  5. requirements.txt +3 -0
  6. stores.csv +1 -0
  7. test.csv +0 -0
  8. train.csv +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ train.csv filter=lfs diff=lfs merge=lfs -text
Sales forecasting.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import datetime
4
+ import pickle
5
+
6
+ # Step 1
7
+ def extract_week(df):
8
+ try:
9
+ df['Date'] = pd.to_datetime(df['Date'])
10
+ df['Week'] = df['Date'].dt.isocalendar().week
11
+ df['Year'] = pd.DatetimeIndex(df['Date']).year
12
+ df['Month'] = pd.DatetimeIndex(df['Date']).month
13
+ except Exception as e:
14
+ st.error(f"Error during date extraction: {str(e)}")
15
+ return df
16
+
17
+ # Step 2
18
+ def maping_type(df):
19
+ try:
20
+ df['Type'] = df['Type'].map({'A': 1, 'B': 2, 'C': 3}) # Convert to integer directly
21
+ except Exception as e:
22
+ st.error(f"Error during type mapping: {str(e)}")
23
+ return df
24
+
25
+ # Step 3
26
+ def convert_to_int(df):
27
+ try:
28
+ df['Type'] = df['Type'].astype(int)
29
+ df['IsHoliday'] = df['IsHoliday'].astype(int)
30
+ except Exception as e:
31
+ st.error(f"Error during data type conversion: {str(e)}")
32
+ return df
33
+
34
+ # Step 4
35
+ def input_col_sel(df):
36
+ input_col = ['Store', 'Dept', 'IsHoliday', 'Type', 'Size', 'Temperature',
37
+ 'Fuel_Price', 'CPI', 'Unemployment', 'Week', 'Year', 'Month',
38
+ 'Fuel_Price_Cat']
39
+ return df[input_col]
40
+
41
+ def load_model():
42
+ try:
43
+ # Load the pre-trained model from the pickle file
44
+ model = pickle.load(open('model.pkl', 'rb'))
45
+ return model
46
+ except Exception as e:
47
+ st.error(f"Error loading the model: {str(e)}")
48
+ return None
49
+
50
+ def predict_sales(model, input_data):
51
+ try:
52
+ # Make predictions using the loaded model
53
+ # Replace this line with the appropriate prediction logic based on your model
54
+ prediction = model.predict(input_data)
55
+ return prediction
56
+ except Exception as e:
57
+ st.error(f"Error during prediction: {str(e)}")
58
+ return None
59
+
60
+ def main():
61
+ st.title("Walmart Sales Forecasting App")
62
+
63
+ # Create input fields for manual input
64
+ st.sidebar.header("Inputs")
65
+ store = st.sidebar.number_input("Store", min_value=1, max_value=45, step=1, value=1)
66
+ dept = st.sidebar.number_input("Dept", min_value=1, max_value=99, step=1, value=1)
67
+ is_holiday = st.sidebar.checkbox("Is Holiday")
68
+ type_input = st.sidebar.selectbox("Type", ['A', 'B', 'C'])
69
+ size = st.sidebar.number_input("Size", min_value=34875, max_value=219622, step=1, value=34875)
70
+ temperature = st.sidebar.number_input("Temperature", min_value=-2, max_value=100)
71
+ fuel_price = st.sidebar.number_input("Fuel Price", min_value=2.5, max_value=4.4)
72
+ cpi = st.sidebar.number_input("CPI", min_value=126, max_value=227)
73
+ unemployment = st.sidebar.number_input("Unemployment", min_value=3.879, max_value=14.00, value=3.879)
74
+ min_date = datetime.date(2010, 3, 1) # Minimum allowed date
75
+ input_date = st.sidebar.date_input("Date", min_value=min_date, value=datetime.date.today())
76
+ fuel_price_cat = st.sidebar.number_input("Fuel Price Category", min_value=2.00, max_value=4.25)
77
+
78
+ # Create a dataframe from manual input
79
+ input_data = pd.DataFrame({
80
+ 'Store': [store],
81
+ 'Dept': [dept],
82
+ 'IsHoliday': [int(is_holiday)],
83
+ 'Type': [type_input],
84
+ 'Size': [size],
85
+ 'Temperature': [temperature],
86
+ 'Fuel_Price': [fuel_price],
87
+ 'CPI': [cpi],
88
+ 'Unemployment': [unemployment],
89
+ 'Date': [input_date], # Use the manually input date
90
+ 'Fuel_Price_Cat': [fuel_price_cat]
91
+ })
92
+
93
+ # Load the model
94
+ model = load_model()
95
+
96
+ if model is not None and st.button("Predict Sales Amount"):
97
+ # Apply the preprocessing steps to the manual input
98
+ input_data = extract_week(input_data)
99
+ input_data = maping_type(input_data)
100
+ input_data = convert_to_int(input_data)
101
+ input_data = input_col_sel(input_data)
102
+
103
+ # Make predictions
104
+ prediction = predict_sales(model, input_data)
105
+
106
+ if prediction is not None:
107
+ st.success(f"Prediction: {prediction}")
108
+
109
+ if __name__ == "__main__":
110
+ main()
features.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit==0.90.0
2
+ pandas==1.3.3
3
+ scikit-learn==0.24.2
stores.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Store,Type,Size
test.csv ADDED
The diff for this file is too large to render. See raw diff
 
train.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65834f65a2ddccc85d8f4bf6544f73625be553f8ca5f8fdee976b9d0c900e95d
3
+ size 12842546