eyad222 commited on
Commit
8db4111
·
verified ·
1 Parent(s): ee8bdec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -26
app.py CHANGED
@@ -16,19 +16,6 @@ def prediction_pop_model(year, population, pred_year):
16
  pred_population = slope * (pred_year) + intercept
17
  return pred_population
18
 
19
- def number_to_words(number):
20
- # Simple conversion function for demonstration
21
- ones = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
22
- tens = ['', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
23
- teens = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
24
-
25
- if number < 10:
26
- return ones[number]
27
- elif number < 20:
28
- return teens[number - 10]
29
- else:
30
- return tens[number // 10] + ' ' + ones[number % 10]
31
-
32
  # Data
33
  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)
34
  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)
@@ -42,31 +29,30 @@ input_year = st.number_input("Enter the year you want to predict the population
42
  # Predict button
43
  if st.button("Predict"):
44
  predicted_population = prediction_pop_model(year, population, input_year)
45
- population_words = number_to_words(int(predicted_population))
46
- st.write(f"Predicted Population for {input_year}: {population_words}")
47
 
48
- # Plotting
49
- fig = plt.figure(figsize=(10, 5))
50
- ax = fig.add_subplot(111, projection='3d')
 
 
51
  ax.scatter(year, population, zs=0, zdir='z', color='blue', label='Actual Population')
52
  ax.plot(year, population, zs=0, zdir='z', color='blue')
53
  ax.scatter([input_year], [predicted_population], zs=0, zdir='z', color='red', label='Predicted Population')
54
-
55
  ax.set_xlabel('Year')
56
  ax.set_ylabel('Population')
57
  ax.set_zlabel('Values')
58
- ax.set_title('Population Prediction')
59
  ax.legend()
60
 
61
- st.pyplot(fig)
62
-
63
- # 2D Plot for comparison
64
- plt.figure(figsize=(10, 5))
65
  plt.scatter(year, population, color='blue', label='Actual Population')
66
  plt.plot(year, population, color='blue')
67
  plt.scatter(input_year, predicted_population, color='red', label='Predicted Population')
68
  plt.xlabel('Year')
69
  plt.ylabel('Population')
70
- plt.title('Population Prediction')
71
  plt.legend()
72
- st.pyplot(plt.gcf())
 
 
16
  pred_population = slope * (pred_year) + intercept
17
  return pred_population
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Data
20
  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)
21
  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)
 
29
  # Predict button
30
  if st.button("Predict"):
31
  predicted_population = prediction_pop_model(year, population, input_year)
32
+ st.write(f"Predicted Population for {input_year}: {predicted_population:.2f} million")
 
33
 
34
+ # Plotting 3D and 2D
35
+ fig = plt.figure(figsize=(15, 7))
36
+
37
+ # 3D plot
38
+ ax = fig.add_subplot(121, projection='3d')
39
  ax.scatter(year, population, zs=0, zdir='z', color='blue', label='Actual Population')
40
  ax.plot(year, population, zs=0, zdir='z', color='blue')
41
  ax.scatter([input_year], [predicted_population], zs=0, zdir='z', color='red', label='Predicted Population')
 
42
  ax.set_xlabel('Year')
43
  ax.set_ylabel('Population')
44
  ax.set_zlabel('Values')
45
+ ax.set_title('Population Prediction (3D)')
46
  ax.legend()
47
 
48
+ # 2D plot
49
+ plt.subplot(122)
 
 
50
  plt.scatter(year, population, color='blue', label='Actual Population')
51
  plt.plot(year, population, color='blue')
52
  plt.scatter(input_year, predicted_population, color='red', label='Predicted Population')
53
  plt.xlabel('Year')
54
  plt.ylabel('Population')
55
+ plt.title('Population Prediction (2D)')
56
  plt.legend()
57
+
58
+ st.pyplot(fig)