File size: 6,309 Bytes
85d8d22
80d8569
85d8d22
 
80d8569
 
 
85d8d22
525e0e6
a7e7f8b
80d8569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f24789e
 
 
 
 
 
 
 
 
 
 
 
 
80d8569
f24789e
80d8569
f24789e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d8569
 
f24789e
80d8569
f24789e
 
 
 
80d8569
f24789e
80d8569
 
 
 
f24789e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d8569
f24789e
80d8569
 
f24789e
 
 
 
 
 
 
 
 
80d8569
f24789e
 
 
 
 
 
 
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
174
175
176
177
178
179
180
import streamlit as st

# Set Streamlit page configuration at the very top
st.set_page_config(page_title="E-Commerce Pricing Optimization", layout="wide")

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt



# Set random seed for reproducibility
np.random.seed(42)

# Generate synthetic data for an e-commerce store
num_products = 100  # Number of products

# Product categories
categories = ["Electronics", "Clothing", "Home & Kitchen", "Beauty", "Sports"]
product_names = [f"Product_{i+1}" for i in range(num_products)]
category_data = np.random.choice(categories, num_products)

# Base price range per category
price_ranges = {
    "Electronics": (50, 500),
    "Clothing": (10, 100),
    "Home & Kitchen": (20, 300),
    "Beauty": (5, 50),
    "Sports": (15, 200),
}

# Generate base prices based on category
base_prices = [np.random.uniform(*price_ranges[cat]) for cat in category_data]

# Competitor pricing (fluctuating around base price)
competitor_prices = [price * np.random.uniform(0.9, 1.1) for price in base_prices]

# Seasonal demand factor (scale between 0.5 and 1.5)
seasonality = np.random.uniform(0.5, 1.5, num_products)

# Customer demand (influenced by price and seasonality)
demand = [(200 / price) * season * np.random.uniform(0.8, 1.2) for price, season in zip(base_prices, seasonality)]

# Assemble dataset
ecommerce_data = pd.DataFrame({
    "Product": product_names,
    "Category": category_data,
    "Base_Price": base_prices,
    "Competitor_Price": competitor_prices,
    "Seasonality_Factor": seasonality,
    "Demand": demand
})

# Load the synthetic dataset (Replace this with actual dataset loading)
@st.cache_data
def load_data():
    return ecommerce_data  # Use the generated dataset from previous steps

data = load_data()

import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.cluster import KMeans
import pandas as pd

# App Title
st.title("Business Performance Analysis")

# Sidebar Navigation
st.sidebar.header("Navigation")
page = st.sidebar.selectbox("Select a Page", ["Introduction", "Visualizations", "Solution", "Forecasting", "Customer Segmentation", "Expense Optimization", "Goal Tracker"])

# Page 1: Introduction
if page == "Introduction":
    st.header("πŸ“Œ Introduction")
    st.markdown("""
    ## Understanding the Business Problem
    Businesses today face significant challenges in optimizing **profitability, reducing costs, and maximizing customer value**.
    Here are three key business issues:

    1️⃣ **Revenue and Profitability Issues**
       - Unpredictable revenue impacts long-term growth.
       - High operational costs reduce net profit margins.

    2️⃣ **Customer Retention & Engagement**
       - Businesses struggle to understand customer behavior.
       - Acquiring new customers is costlier than retaining existing ones.

    3️⃣ **Data-Driven Decision Making**
       - Many businesses lack real-time insights.
       - Without proper data analysis, decisions are based on intuition rather than facts.

    ### πŸ” Our Key Approaches
    - **Revenue & Cost Analysis**
    - **Data Visualization for Business Insights**
    - **Strategic Business Solutions**
    - **Forecasting Future Trends**
    - **Competitor Benchmarking**
    - **Customer Segmentation**
    - **Expense Optimization**
    - **Goal Tracking & Business Strategy**
    """)

# Page 2: Visualizations
elif page == "Visualizations":
    st.header("πŸ“Š Business Data Visualizations")
    st.subheader("πŸ“ˆ Revenue vs Costs")
    revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
    costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)
    fig, ax = plt.subplots()
    ax.bar(["Revenue", "Costs"], [revenue, costs], color=['green', 'red'])
    st.pyplot(fig)



# Page 3: Solution
elif page == "Solution":
    st.header("πŸ“ˆ Business Solution & Insights")
    st.subheader("πŸ“Š Key Business Metrics")
    # Define revenue and costs globally so they can be accessed on multiple pages
    revenues = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
    costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)

    # Calculate profit using global revenue and costs
    profit = revenues - costs

    # Display the result
    st.metric(label="Total Profit ($)", value=f"${profit:,.2f}")


# Page 4: Forecasting
elif page == "Forecasting":
    st.header("πŸ“ˆ Future Revenue Prediction")
    months = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)
    revenue_data = np.array([8000, 8500, 9000, 9400, 10000, 10500])
    model = LinearRegression()
    model.fit(months, revenue_data)
    future_months = np.array([7, 8, 9]).reshape(-1, 1)
    predicted_revenue = model.predict(future_months)
    st.line_chart(np.append(revenue_data, predicted_revenue))

# Page 5: Customer Segmentation
elif page == "Customer Segmentation":
    st.header("πŸ›’ Customer Segmentation")
    customer_data = pd.DataFrame({
        'revenue': [200, 500, 800, 1200, 1500, 300],
        'purchases': [2, 5, 8, 12, 15, 3]
    })
    kmeans = KMeans(n_clusters=3)
    customer_data['segment'] = kmeans.fit_predict(customer_data)
    st.scatter_chart(customer_data, x='revenue', y='purchases', color='segment')

# Page 6: Expense Optimization
elif page == "Expense Optimization":
    st.header("πŸ’° Expense Optimization")
    expense_categories = ["Marketing", "Salaries", "Infrastructure", "Miscellaneous"]
    expenses = [3000, 5000, 2000, 1000]
    fig, ax = plt.subplots()
    ax.pie(expenses, labels=expense_categories, autopct='%1.1f%%', startangle=140)
    st.pyplot(fig)

# Page 7: Goal Tracker
elif page == "Goal Tracker":
    st.header("🎯 Business Goal Tracker")

# User inputs revenue goal
    goal = st.number_input("Enter your revenue goal ($)", min_value=0)

# User inputs monthly revenue
    revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)

# Check if the goal is met
    if goal < revenue:
      st.warning("You have reached your revenue goal yet.")
    else:
      progress = (revenue / goal) * 100 if goal else 0
      st.progress(progress / 100)
      st.write(f"**Progress:** {progress:.2f}% of goal achieved")