Python Forum
Loop to find the best combination/score
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop to find the best combination/score
#11
Hello everyone,

I modified my code, it should be faster than the last one above, but still pretty long when I need to find 5 of 60...
Instead of comparing every combination like before, I putting in a dict index/score, then I sort by score and looking at the first indexes where sum-average) - sum(MVP) is under 121:
    df1 = pd.DataFrame.from_dict(data)
    for index in list(combinations(df1.index,5)):
        dictIndexScore[index] = df1.loc[index,:]["Score1"].sum(axis=0)
    for i in sorted(dictIndexScore.items(), key=lambda x:x[1], reverse=True):
        if df1.loc[i[0],:]["10Aver1"].sum(axis=0) - df1.loc[i[0],:]["10Aver1"].max(axis=0) < 121:
            bestIndex = i[0]
            bestSum = i[1]
            break

    print(df1.loc[bestIndex,:])
My program did 3366.6575298309326 seconds for a 60 rows dataframe, so 5461512 combinations possible of 5 in 60...

Do you have any tips/hints to go faster ?
I read numpy is faster than dataframe, but didn't really work yet with it
Reply


Messages In This Thread
RE: Loop to find the best combination/score - by KoinKoin - Dec-30-2022, 04:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update score value? Mavoz 5 2,621 Nov-08-2022, 12:37 AM
Last Post: Mavoz
  Algorithm to generate a combination guvinicius2 5 2,670 Aug-15-2020, 10:42 PM
Last Post: deanhystad
  loops in combination with lists Juru 4 2,893 May-07-2020, 02:58 PM
Last Post: Marbelous
  Average score MartinEvtimov 5 6,978 Apr-02-2017, 07:35 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020