【问题标题】:How to predict a specific row in a column using a prediction model python?如何使用预测模型python预测列中的特定行?
【发布时间】:2019-08-05 02:20:46
【问题描述】:

我有以下有效的代码:

for model in models:
    model.fit(trainset)
    predictions = model.test(testset)
    top_n = get_top_n(predictions, n=5)

    # Print the first one
    user = list(top_n.keys())[0]
    print(f'model: {model}, {user}: {top_n[user]}')
print('Top N computation successful!')

但挑战在于——我正在尝试使用该模型来预测足球比赛。感兴趣的两列是:home_gameaway_game

这些列中感兴趣的两项是:ChelseaWest Ham

使用上述模型有条件地选择这两项的最佳方法是什么?

【问题讨论】:

    标签: python pandas algorithm data-science prediction


    【解决方案1】:

    我假设您的数据框看起来像这样:

    df = pd.DataFrame({'home_game':['Man Utd', 'Chelsea', 'Arsenal'], 'away_game':['Liverpool','West Ham','Spurs']})
    
        away_game   home_game
    0   Liverpool   Man Utd
    1   West Ham    Chelsea
    2   Spurs       Arsenal
    

    您可以通过这种方式选择切尔西和西汉姆联队:

    test = df[(df['home_game'] == 'Chelsea') & (df['away_game'] == 'West Ham')]
    

    并通过传递结果数据框来预测这一点(取决于您的模型预测功能):

    model.predict(test) 
    

    【讨论】:

    • 好的,我试试看。
    • 我刚刚做了,我得到了这个TypeError: predict() missing 1 required positional argument: 'iid'
    • 您能否用您现有的数据框和经过训练的特定模型更新您的示例?
    • # list of models models = [model_random, model_svd, model_svdpp, model_nmf, model_slopeone, model_knnbasic, model_knnwithmeans,model_knnbaseline, model_coclustering, model_baselineonly, model_knnwithzscore, model_user, model_item]
    猜你喜欢
    • 2020-03-15
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 2020-08-24
    • 2016-03-08
    • 1970-01-01
    • 2020-08-24
    • 2021-07-01
    相关资源
    最近更新 更多