Spaces:
Sleeping
Sleeping
Commit
·
9042810
1
Parent(s):
7d57108
error while calculating tiktok spend
Browse files
marginal_cpc_calculator.py
CHANGED
@@ -72,6 +72,7 @@ def calculate_max_spend(df,min_date,max_date,
|
|
72 |
df_temp['marginal_income'] = df_temp.cum_income - df_temp.cum_income.shift(1) - df_temp['marginal_cpc']
|
73 |
|
74 |
try:
|
|
|
75 |
params, cv = curve_fit(polynomial_func, df_temp['cum_cost'],df_temp['marginal_income'].fillna(0), p0=(1, 1,1,1))
|
76 |
a,b,c,d = params
|
77 |
|
@@ -79,7 +80,7 @@ def calculate_max_spend(df,min_date,max_date,
|
|
79 |
squaredDiffs = np.square(df_temp['marginal_income'].fillna(0) - polynomial_func(df_temp['cum_cost'], a,b,c,d))
|
80 |
squaredDiffsFromMean = np.square(df_temp['marginal_income'].fillna(0) - np.mean(df_temp['marginal_income'].fillna(0)))
|
81 |
rSquared = 1 - np.sum(squaredDiffs) / np.sum(squaredDiffsFromMean)
|
82 |
-
|
83 |
if pprint==True:
|
84 |
output_msg.append(f"R² of fit for marginal income = {rSquared}")
|
85 |
# print(f"R² of fit for marginal income = {rSquared}")
|
|
|
72 |
df_temp['marginal_income'] = df_temp.cum_income - df_temp.cum_income.shift(1) - df_temp['marginal_cpc']
|
73 |
|
74 |
try:
|
75 |
+
output_msg=[]
|
76 |
params, cv = curve_fit(polynomial_func, df_temp['cum_cost'],df_temp['marginal_income'].fillna(0), p0=(1, 1,1,1))
|
77 |
a,b,c,d = params
|
78 |
|
|
|
80 |
squaredDiffs = np.square(df_temp['marginal_income'].fillna(0) - polynomial_func(df_temp['cum_cost'], a,b,c,d))
|
81 |
squaredDiffsFromMean = np.square(df_temp['marginal_income'].fillna(0) - np.mean(df_temp['marginal_income'].fillna(0)))
|
82 |
rSquared = 1 - np.sum(squaredDiffs) / np.sum(squaredDiffsFromMean)
|
83 |
+
|
84 |
if pprint==True:
|
85 |
output_msg.append(f"R² of fit for marginal income = {rSquared}")
|
86 |
# print(f"R² of fit for marginal income = {rSquared}")
|