-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
28 lines (21 loc) · 1001 Bytes
/
main.py
File metadata and controls
28 lines (21 loc) · 1001 Bytes
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
import math
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from tools import exponential, logistic
from tools import get_exponential_params, get_logistic_params
df = pd.read_csv("data.csv")
df["t_year"] = df["year"] - df.iloc[0]["year"]
r_exp, P_init_exp = get_exponential_params(df["t_year"], df["population"])
K, r_log, P_init_log = get_logistic_params(df["t_year"], df["population"])
years = [i for i in range(1850, 2021)]
predicted_populations_exp = [exponential(year - df.iloc[0]["year"], r_exp, P_init_exp) for year in years]
predicted_populations_log = [logistic(year - df.iloc[0]["year"], K, r_log, P_init_log) for year in years]
plt.plot(years, predicted_populations_exp, color="blue", label="exponential")
plt.plot(years, predicted_populations_log, color="green", label="logistic")
plt.scatter(df["year"], df["population"], color="red", label="Census Data")
plt.xlabel("Year")
plt.ylabel("Population")
plt.title("Population Over Time")
plt.legend()
plt.show()