Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
1
Indexable
Never
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
# import knime.scripting.io as knio

start_date = pd.to_datetime("2024-02-02")
end_date = pd.to_datetime("2024-02-28")

initial_total = 500

def deg_gompertz(x, a, b, c):
    return a * np.exp(-b * np.exp(-c * x))

count_days = (end_date - start_date).days + 1

days = np.arange(1, count_days + 1)  #x

initial_params = [initial_total, 1, 0.05]

# simulated_totals = np.linspace(initial_total, 0, count_days)  #y

# Tim y
li = []
for i in range(count_days):
  y = deg_gompertz(i, 500.3985327, 0.0106358, -0.067043834578)
  temp = random.randrange(-5, 5)
  y += temp
  li.append(y)

# y = list li
print(len(days))
print(li)
params, _ = curve_fit(deg_gompertz, days, li)

print("XXX")
print(params, _)

predicted_totals = deg_gompertz(days, *params)

date_range = pd.date_range(start_date, periods=count_days)
data = pd.DataFrame({'date': date_range, 'total': predicted_totals})

print(data)

plt.figure(figsize=(10, 6))
plt.plot(data['date'], data['total'], marker='o', linestyle='-', color='blue')
plt.title('Degenerating Gompertz Curve for Total')
plt.xlabel('Date')
plt.ylabel('Total')
plt.grid(True)
plt.show()
Leave a Comment