eyad222 commited on
Commit
9cda215
1 Parent(s): d47ee4f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import streamlit as st
3
+ import matplotlib.pyplot as plt
4
+
5
+ def prediction_pop_model(year, population, pred_year):
6
+ n = len(year)
7
+ sum_x = np.sum(year, dtype=np.float64)
8
+ sum_y = np.sum(population, dtype=np.float64)
9
+ sum_xy = np.sum(year * population, dtype=np.float64)
10
+ sum_x_squared = np.sum(year ** 2, dtype=np.float64)
11
+
12
+ slope = (n * sum_xy - sum_x * sum_y) / (n * sum_x_squared - sum_x ** 2)
13
+ intercept = (sum_y - slope * sum_x) / n
14
+
15
+ pred_population = slope * (pred_year) + intercept
16
+ return pred_population
17
+
18
+ # Data
19
+ year = np.array([1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007, 2009, 2011, 2013, 2015, 2017, 2019, 2021, 2023, 2024], dtype=np.float64)
20
+ population = np.array([22223309, 25009741, 28173309, 31681188, 34807417, 38783863, 45681811, 52799062, 59402198, 66134291, 73312559, 75100000, 78300000, 81500000, 85800000, 89000000, 94800000, 98900000, 102800000, 106100000, 107300000], dtype=np.float64)
21
+
22
+ # Streamlit Interface
23
+ st.title("Population Prediction Model")
24
+
25
+ # Input year
26
+ input_year = st.number_input("Enter the year you want to predict the population for:", min_value=1950, max_value=2100, step=1, value=2024)
27
+
28
+ # Predict button
29
+ if st.button("Predict"):
30
+ predicted_population = prediction_pop_model(year, population, input_year)
31
+ st.write(f"Predicted Population for {input_year}: {predicted_population}")
32
+
33
+ # Plotting
34
+ plt.figure(figsize=(10, 5))
35
+ plt.scatter(year, population, color='blue', label='Actual Population')
36
+ plt.plot(year, population, color='blue')
37
+ plt.scatter(input_year, predicted_population, color='red', label='Predicted Population')
38
+ plt.xlabel('Year')
39
+ plt.ylabel('Population')
40
+ plt.title('Population Prediction')
41
+ plt.legend()
42
+ st.pyplot(plt.gcf())