James McCool
commited on
Commit
·
2f8b929
1
Parent(s):
8d3abd2
Refactor lineup selection logic in large_field_preset.py to improve accuracy and efficiency. Replaced the previous iterative approach with a method that calculates evenly spaced target similarity scores, ensuring a more precise selection of lineups based on similarity while avoiding duplicates.
Browse files
global_func/large_field_preset.py
CHANGED
@@ -1,30 +1,29 @@
|
|
1 |
import pandas as pd
|
|
|
2 |
|
3 |
def large_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
|
4 |
-
|
5 |
excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Similarity Score']
|
6 |
player_columns = [col for col in portfolio.columns if col not in excluded_cols]
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
for team in portfolio['Stack'].unique():
|
12 |
-
rows_to_drop = []
|
13 |
-
working_portfolio = portfolio.copy()
|
14 |
-
working_portfolio = working_portfolio[working_portfolio['Stack'] == team].sort_values(by='Similarity Score', ascending = True)
|
15 |
-
working_portfolio = working_portfolio.reset_index(drop=True)
|
16 |
-
curr_own_type_max = working_portfolio.loc[0, 'median'] + (slack_var / 20 * working_portfolio.loc[0, 'median'])
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
|
4 |
def large_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
|
|
|
5 |
excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Similarity Score']
|
6 |
player_columns = [col for col in portfolio.columns if col not in excluded_cols]
|
7 |
|
8 |
+
concat_portfolio = portfolio.copy()
|
9 |
+
concat_portfolio = concat_portfolio.sort_values(by='Similarity Score', ascending=True).reset_index(drop=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Calculate target similarity scores for linear progression
|
12 |
+
similarity_floor = concat_portfolio['Similarity Score'].min()
|
13 |
+
similarity_ceiling = concat_portfolio['Similarity Score'].max()
|
14 |
+
|
15 |
+
# Create evenly spaced target similarity scores
|
16 |
+
target_similarities = np.linspace(similarity_floor, similarity_ceiling, lineup_target)
|
17 |
+
|
18 |
+
# Find the closest lineup to each target similarity score
|
19 |
+
selected_indices = []
|
20 |
+
for target_sim in target_similarities:
|
21 |
+
# Find the index of the closest similarity score
|
22 |
+
closest_idx = (concat_portfolio['Similarity Score'] - target_sim).abs().idxmin()
|
23 |
+
if closest_idx not in selected_indices: # Avoid duplicates
|
24 |
+
selected_indices.append(closest_idx)
|
25 |
+
|
26 |
+
# Select the lineups
|
27 |
+
concat_portfolio = concat_portfolio.loc[selected_indices].reset_index(drop=True)
|
28 |
+
|
29 |
+
return concat_portfolio.sort_values(by='median', ascending=False)
|