James McCool
commited on
Commit
·
5dc36a5
1
Parent(s):
5244b28
Add weighted ownership calculation in predict_dupes.py: implement a new function to calculate weighted ownership values, enhancing the accuracy of ownership metrics in portfolio analysis.
Browse files- global_func/predict_dupes.py +29 -1
global_func/predict_dupes.py
CHANGED
@@ -5,6 +5,34 @@ import time
|
|
5 |
from fuzzywuzzy import process
|
6 |
import math
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, strength_var, sport_var):
|
9 |
if strength_var == 'Weak':
|
10 |
dupes_multiplier = .75
|
@@ -229,7 +257,7 @@ def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, streng
|
|
229 |
portfolio['Lineup Edge'] = portfolio['Win%'] * ((.5 - portfolio['Finish_percentile']) * (Contest_Size / 2.5))
|
230 |
portfolio['Lineup Edge'] = portfolio.apply(lambda row: row['Lineup Edge'] / (row['Dupes'] + 1) if row['Dupes'] > 0 else row['Lineup Edge'], axis=1)
|
231 |
portfolio['Lineup Edge'] = portfolio['Lineup Edge'] - portfolio['Lineup Edge'].mean()
|
232 |
-
portfolio['Weighted Own'] =
|
233 |
portfolio['Geomean'] = np.power((portfolio[own_columns] * 100).product(axis=1), 1 / len(own_columns))
|
234 |
portfolio = portfolio.drop(columns=dup_count_columns)
|
235 |
portfolio = portfolio.drop(columns=own_columns)
|
|
|
5 |
from fuzzywuzzy import process
|
6 |
import math
|
7 |
|
8 |
+
def calculate_weighted_ownership(row_ownerships):
|
9 |
+
"""
|
10 |
+
Calculate weighted ownership based on the formula:
|
11 |
+
(AVERAGE of (each value's average with overall average)) * count - (max - min)
|
12 |
+
|
13 |
+
Args:
|
14 |
+
row_ownerships: Series containing ownership values for a row
|
15 |
+
|
16 |
+
Returns:
|
17 |
+
float: Calculated weighted ownership value
|
18 |
+
"""
|
19 |
+
# Get the mean of all ownership values
|
20 |
+
row_mean = row_ownerships.mean()
|
21 |
+
|
22 |
+
# Calculate average of each value with the overall mean
|
23 |
+
value_means = [(val + row_mean) / 2 for val in row_ownerships]
|
24 |
+
|
25 |
+
# Take average of all those means
|
26 |
+
avg_of_means = sum(value_means) / len(value_means)
|
27 |
+
|
28 |
+
# Multiply by count of values
|
29 |
+
weighted = avg_of_means * len(row_ownerships)
|
30 |
+
|
31 |
+
# Subtract (max - min)
|
32 |
+
weighted = weighted - (row_ownerships.max() - row_ownerships.min())
|
33 |
+
|
34 |
+
return weighted
|
35 |
+
|
36 |
def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, strength_var, sport_var):
|
37 |
if strength_var == 'Weak':
|
38 |
dupes_multiplier = .75
|
|
|
257 |
portfolio['Lineup Edge'] = portfolio['Win%'] * ((.5 - portfolio['Finish_percentile']) * (Contest_Size / 2.5))
|
258 |
portfolio['Lineup Edge'] = portfolio.apply(lambda row: row['Lineup Edge'] / (row['Dupes'] + 1) if row['Dupes'] > 0 else row['Lineup Edge'], axis=1)
|
259 |
portfolio['Lineup Edge'] = portfolio['Lineup Edge'] - portfolio['Lineup Edge'].mean()
|
260 |
+
portfolio['Weighted Own'] = portfolio[own_columns].apply(calculate_weighted_ownership, axis=1)
|
261 |
portfolio['Geomean'] = np.power((portfolio[own_columns] * 100).product(axis=1), 1 / len(own_columns))
|
262 |
portfolio = portfolio.drop(columns=dup_count_columns)
|
263 |
portfolio = portfolio.drop(columns=own_columns)
|