3v324v23 commited on
Commit
26e2233
Β·
1 Parent(s): fe2ce5b
Files changed (4) hide show
  1. app.py +91 -0
  2. decision_tree_model.pkl +3 -0
  3. file.csv +0 -0
  4. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ from sklearn.model_selection import train_test_split
7
+ from sklearn.tree import DecisionTreeClassifier
8
+ from sklearn.preprocessing import LabelEncoder
9
+
10
+ st.title("πŸ›’ Online Shopping Recommendation System")
11
+
12
+ # Load dataset
13
+ csv_path = "file.csv"
14
+ df = pd.read_csv(csv_path)
15
+
16
+ # Handle categorical columns by encoding them
17
+ label_encoders = {}
18
+ for col in df.select_dtypes(include=['object']).columns:
19
+ le = LabelEncoder()
20
+ df[col] = le.fit_transform(df[col])
21
+ label_encoders[col] = le
22
+
23
+ # Select relevant features
24
+ features = ['Avg_Price', 'Delivery_Charges', 'Discount_pct', 'Online_Spend', 'Offline_Spend', 'Tenure_Months']
25
+ target = 'Coupon_Status'
26
+
27
+ df = df.dropna() # Remove missing values
28
+ X = df[features]
29
+ y = df[target]
30
+
31
+ # Split data into train and test sets
32
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
33
+
34
+ # Train Decision Tree model
35
+ model = DecisionTreeClassifier()
36
+ model.fit(X_train, y_train)
37
+
38
+ # Save the model
39
+ joblib.dump(model, "decision_tree_model.pkl")
40
+
41
+ # Streamlit app with three tabs
42
+ tab1, tab2, tab3 = st.tabs(["πŸ“Š Dataset & Summary", "πŸ“ˆ Data Visualization", "πŸ” Prediction"])
43
+
44
+ # Tab 1: Dataset & Summary
45
+ with tab1:
46
+ st.subheader("Dataset Overview")
47
+ st.write(df) # Show full dataset
48
+ st.write("### Summary Statistics")
49
+ st.write(df.describe())
50
+
51
+ # Tab 2: Data Visualization
52
+ with tab2:
53
+ st.subheader("πŸ“Š Correlation Matrix")
54
+ fig, ax = plt.subplots(figsize=(10, 6))
55
+ sns.heatmap(df.corr(), annot=True, cmap="coolwarm", fmt=".2f", ax=ax)
56
+ st.pyplot(fig)
57
+
58
+ st.subheader("πŸ“Š Pairplot")
59
+ pairplot_fig = sns.pairplot(df[features])
60
+ st.pyplot(pairplot_fig)
61
+
62
+ st.subheader("πŸ“Š Feature Importance (Decision Tree)")
63
+ feature_importance_fig, ax = plt.subplots()
64
+ feature_importances = pd.Series(model.feature_importances_, index=features)
65
+ feature_importances.nlargest(6).plot(kind='barh', ax=ax)
66
+ st.pyplot(feature_importance_fig)
67
+
68
+ # Tab 3: Prediction
69
+ with tab3:
70
+ st.subheader("πŸ” Make a Prediction")
71
+
72
+ # User inputs
73
+ avg_price = st.number_input("Average Price of Product", min_value=0.0, step=1.0)
74
+ delivery_charges = st.number_input("Delivery Charges", min_value=0.0, step=0.5)
75
+ discount_pct = st.number_input("Discount Percentage", min_value=0.0, max_value=100.0, step=1.0)
76
+ online_spend = st.number_input("Online Spend", min_value=0.0, step=10.0)
77
+ offline_spend = st.number_input("Offline Spend", min_value=0.0, step=10.0)
78
+ tenure = st.number_input("Tenure in Months", min_value=0, step=1)
79
+
80
+ if st.button("Predict Coupon Usage"):
81
+ # Load trained model
82
+ model = joblib.load("decision_tree_model.pkl")
83
+
84
+ # Make prediction
85
+ prediction = model.predict([[avg_price, delivery_charges, discount_pct, online_spend, offline_spend, tenure]])
86
+
87
+ # Display result
88
+ if prediction[0] == 1:
89
+ st.success("The customer is likely to use the coupon! πŸŽ‰")
90
+ else:
91
+ st.warning("The customer may not use the coupon.")
decision_tree_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3762309125ef413b35393051171c87e08b80b1746b89fbb4f6a68a70ed2de28
3
+ size 3289825
file.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ joblib
4
+ seaborn
5
+ matplotlib
6
+ scikit-learn