建议表按降序对数据框结果进行排序

2024-05-28 23:51:03 发布

您现在位置:Python中文网/ 问答频道 /正文

推荐表的输出分数没有真正下降,推荐与推荐表的分数不匹配

目前,输入确实有效,并给出了正确的建议表

recommendationTable_df = recommendationTable_df.sort_values(ascending=False)

注意:输出是正确的建议表头(6)

13    1.00
20    1.00
6     0.75
1     0.75
25    0.75
8     0.75

但是,当它显示匹配结果时,它不会按照评分顺序显示id to name。

df.loc[df.index.isin(recommendationTable_df.head(6).keys())] #adjust the value of 6 here

此时,顺序不再是降序或正确的

但它可能是根据我用来匹配名称的id进行排序

    name    herotype    weapons     spells
1   niem    Sorcerer    light crossbow, battleaxe   Necromancy
6   sax     Bard    light crossbow, battleaxe, Dagger, sling, club  Necromancy
8   wuc     Sorcerer    light crossbow, battleaxe   Necromancy
13  Rolf Rylan  Paladin     light crossbow, battleaxe   Necromancy
20  Braak Presley   Paladin     light crossbow, battleaxe, Dagger, sling, club  Necromancy
25  Jantroph    Paladin     light crossbow, battleaxe   Abjuration

分数的顺序应该按照分数的降序将输出与id匹配

这就是我想要实现的目标

userInput = [
            {'name':'Rolf Rylan', 'rating':1}   #Their is no rating system is being used thus by default rating is set to 1
         ] 

推荐表\u df与检查结果匹配这不是真正的数据帧

13    1.00    |    13    Rolf Rylan  Paladin     light crossbow, battleaxe   Necromancy
20    1.00    |    20    Braak Presley   Paladin     light crossbow, battleaxe, Dagger, sling, club  Necromancy
6     0.75    |    6     sax     Bard    light crossbow, battleaxe, Dagger, sling, club  Necromancy
1     0.75    |    1     niem    Sorcerer    light crossbow, battleaxe   Necromancy
25    0.75    |    25    Jantroph    Paladin     light crossbow, battleaxe   Abjuration
8     0.75    |    8     wuc     Sorcerer    light crossbow, battleaxe   Necromancy

我得到的结果与降序顺序不匹配

13    1.00    |    1   niem    Sorcerer    light crossbow, battleaxe   Necromancy
20    1.00    |    6   sax     Bard    light crossbow, battleaxe, Dagger, sling, club  Necromancy
6     0.75    |    8   wuc     Sorcerer    light crossbow, battleaxe   Necromancy
1     0.75    |    13  Rolf Rylan  Paladin     light crossbow, battleaxe   Necromancy
25    0.75    |    20  Braak Presley   Paladin     light crossbow, battleaxe, Dagger, sling, club  Necromancy
8     0.75    |    25  Jantroph    Paladin     light crossbow, battleaxe   Abjuration

如何使推荐数据框架与推荐表输出分数的顺序相匹配

这是推荐表输出分数 哪些是正确的顺序

recommendationTable_df.head(6)

输出

13    1.00
20    1.00
6     0.75
1     0.75
25    0.75
8     0.75
dtype: float64

这是对分数进行排序的方式

#Multiply the genres by the weights and then take the weighted average
recommendationTable_df = ((genreTable*userProfile).sum(axis=1))/(userProfile.sum())

#Sort our recommendations in descending order
recommendationTable_df = recommendationTable_df.sort_values(ascending=False)

df.loc[df.index.isin(recommendationTable_df.head(6).keys())] #adjust the value of 6 here

这是当前的建议此顺序不正确

    name    herotype    weapons     spells
1   niem    Sorcerer    light crossbow, battleaxe   Necromancy
6   sax     Bard    light crossbow, battleaxe, Dagger, sling, club  Necromancy
8   wuc     Sorcerer    light crossbow, battleaxe   Necromancy
13  Rolf Rylan  Paladin     light crossbow, battleaxe   Necromancy
20  Braak Presley   Paladin     light crossbow, battleaxe, Dagger, sling, club  Necromancy
25  Jantroph    Paladin     light crossbow, battleaxe   Abjuration

这是我尝试或期望得到的结果

        name    herotype    weapons     spells
    13  Rolf Rylan  Paladin     light crossbow, battleaxe   Necromancy
    20  Braak Presley   Paladin     light crossbow, battleaxe, Dagger, sling, club  Necromancy
    6   sax     Bard    light crossbow, battleaxe, Dagger, sling, club  Necromancy
    1   niem    Sorcerer    light crossbow, battleaxe   Necromancy
    25  Jantroph    Paladin     light crossbow, battleaxe   Abjuration
    8   wuc     Sorcerer    light crossbow, battleaxe   Necromancy

基于输出


   13    1.00
   20    1.00
   6     0.75
   1     0.75
   25    0.75
   8     0.75
   dtype: float64

Tags: df顺序paladin分数lightclubdaggercrossbow
1条回答
网友
1楼 · 发布于 2024-05-28 23:51:03

正如PMende在评论中指出的,我改变了

df.loc[df.index.isin(recommendationTable_df.head(3).keys())] 

进入

df.loc[recommendationTable_df.head(6).index, :]

现在它确实匹配了

#Multiply the genres by the weights and then take the weighted average
recommendationTable_df = ((genreTable*userProfile).sum(axis=1))/(userProfile.sum())

#Sort our recommendations in descending order
recommendationTable_df = recommendationTable_df.sort_values(ascending=False)

#df.loc[df.index.isin(recommendationTable_df.head(3).keys())] #adjust the value of 3 here

df.loc[recommendationTable_df.head(6).index, :]

因此,如果我输入角色名奥多尔·斯伯丁,我会让他以1.0的分数返回奥多尔·斯伯丁,降序匹配顺序

results matching

相关问题 更多 >

    热门问题