Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
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)
|
@@ -15,6 +17,10 @@ def prediction_pop_model(year, population, pred_year):
|
|
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)
|
@@ -28,9 +34,25 @@ input_year = st.number_input("Enter the year you want to predict the population
|
|
28 |
# Predict button
|
29 |
if st.button("Predict"):
|
30 |
predicted_population = prediction_pop_model(year, population, input_year)
|
31 |
-
|
|
|
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')
|
|
|
1 |
import numpy as np
|
2 |
import streamlit as st
|
3 |
import matplotlib.pyplot as plt
|
4 |
+
from mpl_toolkits.mplot3d import Axes3D
|
5 |
+
import inflect
|
6 |
|
7 |
def prediction_pop_model(year, population, pred_year):
|
8 |
n = len(year)
|
|
|
17 |
pred_population = slope * (pred_year) + intercept
|
18 |
return pred_population
|
19 |
|
20 |
+
def number_to_words(number):
|
21 |
+
p = inflect.engine()
|
22 |
+
return p.number_to_words(number)
|
23 |
+
|
24 |
# Data
|
25 |
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)
|
26 |
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)
|
|
|
34 |
# Predict button
|
35 |
if st.button("Predict"):
|
36 |
predicted_population = prediction_pop_model(year, population, input_year)
|
37 |
+
population_words = number_to_words(predicted_population)
|
38 |
+
st.write(f"Predicted Population for {input_year}: {population_words}")
|
39 |
|
40 |
# Plotting
|
41 |
+
fig = plt.figure(figsize=(10, 5))
|
42 |
+
ax = fig.add_subplot(111, projection='3d')
|
43 |
+
ax.scatter(year, population, zs=0, zdir='z', color='blue', label='Actual Population')
|
44 |
+
ax.plot(year, population, zs=0, zdir='z', color='blue')
|
45 |
+
ax.scatter([input_year], [predicted_population], zs=0, zdir='z', color='red', label='Predicted Population')
|
46 |
+
|
47 |
+
ax.set_xlabel('Year')
|
48 |
+
ax.set_ylabel('Population')
|
49 |
+
ax.set_zlabel('Values')
|
50 |
+
ax.set_title('Population Prediction')
|
51 |
+
ax.legend()
|
52 |
+
|
53 |
+
st.pyplot(fig)
|
54 |
+
|
55 |
+
# 2D Plot for comparison
|
56 |
plt.figure(figsize=(10, 5))
|
57 |
plt.scatter(year, population, color='blue', label='Actual Population')
|
58 |
plt.plot(year, population, color='blue')
|