JEPHONETORRE commited on
Commit
5e5c214
ยท
1 Parent(s): e3be123
Files changed (2) hide show
  1. app.py +105 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.linear_model import LinearRegression
6
+ from sklearn.metrics import mean_squared_error, r2_score
7
+ import matplotlib.pyplot as plt
8
+
9
+ # Page Configuration
10
+ st.set_page_config(page_title="Sales Forecasting App", layout="wide")
11
+
12
+ # App Header
13
+ st.markdown("<h1 style='text-align: center; color: white;'>๐Ÿ“ˆ Sales Forecasting App</h1>", unsafe_allow_html=True)
14
+
15
+ # Centered Navigation
16
+ st.markdown("<div style='display: flex; justify-content: center;'>", unsafe_allow_html=True)
17
+ tabs = ["๐Ÿ“Š Data Visualization", "๐Ÿ“ˆ Model Performance", "๐Ÿ”ฎ Prediction"]
18
+ selected_tab = st.radio("Navigation", tabs, horizontal=True, key="navigation")
19
+ st.markdown("</div>", unsafe_allow_html=True)
20
+
21
+ # Example Dataset (Replace with actual data)
22
+ data = {
23
+ "Time": range(1, 13), # e.g., months 1 to 12
24
+ "Sales": [150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700],
25
+ "OnlineAds": [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],
26
+ "SocialMedia": [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]
27
+ }
28
+ df = pd.DataFrame(data)
29
+
30
+ if selected_tab == "๐Ÿ“Š Data Visualization":
31
+ st.markdown("### Preview of Dataset")
32
+ st.dataframe(df)
33
+
34
+ st.markdown("### Data Visualization")
35
+ fig, axes = plt.subplots(1, 3, figsize=(15, 5))
36
+
37
+ axes[0].scatter(df["Time"], df["Sales"], color='blue', alpha=0.7)
38
+ axes[0].set_title("Time vs Sales")
39
+ axes[0].set_xlabel("Time")
40
+ axes[0].set_ylabel("Sales")
41
+
42
+ axes[1].scatter(df["OnlineAds"], df["Sales"], color='green', alpha=0.7)
43
+ axes[1].set_title("Online Ads vs Sales")
44
+ axes[1].set_xlabel("Online Ads")
45
+ axes[1].set_ylabel("Sales")
46
+
47
+ axes[2].scatter(df["SocialMedia"], df["Sales"], color='red', alpha=0.7)
48
+ axes[2].set_title("Social Media vs Sales")
49
+ axes[2].set_xlabel("Social Media")
50
+ axes[2].set_ylabel("Sales")
51
+
52
+ st.pyplot(fig)
53
+
54
+ elif selected_tab == "๐Ÿ“ˆ Model Performance":
55
+ st.markdown("### Train Linear Regression Model")
56
+
57
+ # Features and target
58
+ X = df[["Time", "OnlineAds", "SocialMedia"]] # Independent variables
59
+ y = df["Sales"] # Dependent variable
60
+
61
+ # Split data into training and testing sets
62
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
63
+
64
+ # Create and train the linear regression model
65
+ model = LinearRegression()
66
+ model.fit(X_train, y_train)
67
+
68
+ # Predict on test set
69
+ y_pred = model.predict(X_test)
70
+
71
+ # Model evaluation
72
+ mse = mean_squared_error(y_test, y_pred)
73
+ r2 = r2_score(y_test, y_pred)
74
+
75
+ st.write("Mean Squared Error (MSE):", mse)
76
+ st.write("R-squared (R2):", r2)
77
+
78
+ st.write("### Coefficients and Intercept")
79
+ st.write("Coefficients:", model.coef_)
80
+ st.write("Intercept:", model.intercept_)
81
+
82
+ st.markdown("### Scatter Plot of Predictions vs Actual Values")
83
+ fig, ax = plt.subplots(figsize=(8, 6))
84
+ ax.scatter(y_test, y_pred, alpha=0.7, color='purple')
85
+ ax.set_title("Predicted vs Actual Sales")
86
+ ax.set_xlabel("Actual Sales")
87
+ ax.set_ylabel("Predicted Sales")
88
+ st.pyplot(fig)
89
+
90
+ elif selected_tab == "๐Ÿ”ฎ Prediction":
91
+ st.markdown("### Predict Future Sales")
92
+
93
+ # Input for prediction
94
+ time_input = st.number_input("Time (e.g., month number):", min_value=1, max_value=100, step=1)
95
+ online_ads_input = st.number_input("Online Ads Spend:", min_value=0.0, step=10.0)
96
+ social_media_input = st.number_input("Social Media Spend:", min_value=0.0, step=10.0)
97
+
98
+ if st.button("Predict Sales"):
99
+ future_data = pd.DataFrame({
100
+ "Time": [time_input],
101
+ "OnlineAds": [online_ads_input],
102
+ "SocialMedia": [social_media_input]
103
+ })
104
+ future_sales = model.predict(future_data)
105
+ st.write("Predicted Sales:", future_sales[0])
requirements.txt ADDED
File without changes