根据用户选择对项目进行排名的最佳最佳方法
我已经收到了显示用户预订的列表,现在试图通过考虑所有用户预订来找到一个最佳解决方案来对其进行排序:
例如:
L1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
L2 = ['a', 'c', 'e', 'f', 'g', 'b', 'd']
L3 = ['g', 'f', 'e', 'd', 'a', 'c', 'b']
我将要定义一个重量向量,例如:
weight = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3]
然后将列表转换为数值一个乘以每个列表使用此向量元素,然后对其进行排序。
这是一个好方法吗?有建议吗?
I have received lists that shows user prefrences, now trying to find an optimal solutiont to sort them by considering all the users prefrences:
for example:
L1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
L2 = ['a', 'c', 'e', 'f', 'g', 'b', 'd']
L3 = ['g', 'f', 'e', 'd', 'a', 'c', 'b']
I was about to define a weight vector such as :
weight = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3]
Then converting lists to numerical values an multiply each list with this vector elementwise and then sorting them.
is this a good approach? any suggestion ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的l1,l2,l3列表中的值都是单个字符,那么:
ord()给出字符的Unicode值作为整数。取值并乘以相关的重量。
创建一个2个tuplace的列表(togeed_value,cartar)。
排序该列表。
从新排序列表中打印字符。
输出:
注意:,
因为列表仅包含字母a-> g的组合,并且由于权重下降,所以这只是逆转列表。但是,尝试将例如“ x”放入LN列表之一,看看会发生什么
Assuming that the values in your L1, L2, L3 lists are all single characters then:
ord() gives the Unicode value of a character as an integer. Take that value and multiply by the relevant weight.
Create a list of 2-tuples where (weighted_value, character).
Sort that list.
Print the characters from the newly sorted list.
Output:
Note:
As the lists only contain combinations of the letters a->g and because the weights are descending, this merely reverses the lists. However, try putting e.g., 'x' into one of the Ln lists and see what happens
如果我正确理解,您想通过查看用户的整体投票来获得项目排名?
例如,这里
a
在三个用户中排名第一,另一个用户排名第三,因此应将其视为最好的。如果是的,则可以简单地按列表中每个项目出现的索引的总和进行排序:
这样,您不需要权重就可以将投票转换为数字以对它们进行排序。他们在用户排名中的索引是您需要的“权重”(较小)。
If I understood correctly you want to get the items ranking by looking at the overall votes of the users?
E.g., here
a
was ranked first by two users out of three and the other one ranked it third, so it should be considered the best one.If yes, you can simply sort by the sum of the indices where each item appears in the lists:
This way you don't need weights to convert votes to numbers to sort them. Their indices in the users rankings are the "weights" you need (smaller is better).