如何解决如何在 Power Query 中使用这个 python 函数?
我有一个创建 ELO 评级的 Python 函数。我想在我的数据上使用它,如下所示:
[赢家][输家] 甲乙 甲乙
我想在数据框中返回两列以及函数“compute_elo_ratings”生成的结果。
Python 函数:
import pandas as pd
import numpy as np
from collections import defaultdict
def win_probability(elo,opponent_elo):
# Computes the win probability
return 1.0 / (1 + 10 ** (-(elo - opponent_elo) / 400.0))
def compute_elo_ratings(winners,losers,k=32.0):
# Winners: List of winners
# Losers: List of losers
# Important: These must be ordered chronologically (i.e. first winner and
# loser are those of the first match,and so on).
last_ratings = defaultdict(lambda: 1500)
results = list()
for cur_winner,cur_loser in zip(winners,losers):
cur_elo_winner = last_ratings[cur_winner]
cur_elo_loser = last_ratings[cur_loser]
winner_prob = win_probability(cur_elo_winner,cur_elo_loser)
results.append(
{
"elo_winner": cur_elo_winner,"elo_loser": cur_elo_loser,"winner_prob": winner_prob,}
)
winner_update = k * (1 - winner_prob)
loser_update = k * (0 - (1 - winner_prob))
last_ratings[cur_winner] += winner_update
last_ratings[cur_loser] += loser_update
return results
到目前为止,我已经尝试通过 Python 脚本功能添加脚本,但是这不起作用。
有人知道怎么做吗?谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。