gpt4 book ai didi

python - 赛马预测 scikit learn - 每场比赛多行

转载 作者:行者123 更新时间:2023-12-03 17:00:38 25 4
gpt4 key购买 nike

目标
我想用 Scikit-learn 训练一个模型来预测赛马的结果。我有一个 包含多个特征的 CSV 文件,如位置、年龄、体重、horse_name、race_id 等。
问题
在我的原始 CSV 文件中,每匹马都在一行中表示。位置为 1-8,每场比赛由 8 排组成。然而,当我训练我的模型时,模型将每一行视为一个单独的事件(种族)因此表现不佳。
方法
我试图解决这个问题并创建了一个新的 CSV 文件,其中每一行代表一个种族,特征从 position1、age1、weight1、horse_name1、race_id1 到 position8、age8、weight8、horse_name8、race_id8 (见下文) .但是,在这种情况下使用 Multioutput,我的模型根本没有训练,但注意到 age1、weight1 是获胜者的列,并且确实获得了 100% 的准确率。
想法
我想知道是否有办法解决这个问题。也许可以使用原始文件,但不知何故 告诉模型具有相同race_id 的行必须被视为一个事件 .我可以考虑使用 groupby(race_id) 但我无法将新组输入模型。您也可以为每场比赛使用一个包,就像在对文本数据进行预测时一样。
我实际上被困在这里,所以非常感谢任何建议:)

ORIGINAL DF 

position horse age weight race_id

1 name1 3y 900 1
2 name2 4y 800 1
3 name3 5y 760 1
... ... ... ... ...
8 name8 7y 980 1
1 name9 4y 880 2
... ... ... ... ...
8 name16 5y 770 2

NEW DF

position1 horse1 weight1 race_id1 ... position8 horse8 weight8 race_id8

1 name1 900 1 8 name8 980 1
1 name9 880 2 8 name16 770 2

最佳答案

如果我正确理解您的问题,您希望将旧数据框转换为新数据框并将其提供给您的模型。
您可以使用此代码:

import pandas as pd
import numpy as np

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
df = pd.DataFrame({'position': [1, 2, 3, 4],
'horse': ['name1', 'name2', 'name3', 'name8'],
'age': ['4y', '4y', '5y', '7y'],
'weight': [800, 978, 76, 565],
'race_id': [1, 1, 2, 2]})

groupby_race = df.groupby(['race_id'])
arr = []
for name, group in groupby_race:
r = np.concatenate([row.values for index, row in group.iterrows()])
arr.append(r)
new_df = pd.DataFrame(data=arr, columns = ['position1', 'horse1', 'age1', 'weight1', 'race_id1',
'position2', 'horse2', 'age2', 'weight2', 'race_id2'])

关于python - 赛马预测 scikit learn - 每场比赛多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61385916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com