【问题标题】:SciKit Gradient Boosting - How to combine predictions with initial table?SciKit Gradient Boosting - 如何将预测与初始表相结合?
【发布时间】:2019-09-18 12:22:10
【问题描述】:

我正在尝试使用梯度提升模型来预测梦幻足球的未来得分 - 现在只查看前 2 轮。目前,如果一名球员的预期得分超过 6 分,该模型将返回“1”,否则返回“0”——表明该球员是否是一个好的队长选择。

在我的原始表格中,我有玩家姓名和回合信息来提供上下文,但我在训练算法时删除了这些信息。我的问题是,一旦模型做出预测 - 我如何结合玩家姓名显示这个预测,例如:

PlayerA - 队长预测 = 1

等等

y = ds.isCaptain
GB_table = ds.drop(['Player', 'Round', 'isCaptain', 'Points'], axis=1)

X_train, X_test, y_train, y_test = train_test_split(GB_table, y, test_size=0.2)

baseline = GradientBoostingClassifier(learning_rate=0.01,n_estimators=1500,max_depth=4, min_samples_split=40, min_samples_leaf=7,max_features=4 , subsample=0.95, random_state=10)

baseline.fit(X_train,y_train)
predictors=list(X_train)
feat_imp = pd.Series(baseline.feature_importances_, predictors).sort_values(ascending=False)
feat_imp.plot(kind='bar', title='Importance of Features')
plt.ylabel('Feature Importance Score')

print('Accuracy of GBM on test set: {:.3f}'.format(baseline.score(X_test, y_test)))
pred=baseline.predict(X_test)
print(classification_report(y_test, pred))

上面显示了我的预测结果,但不幸的是,由于我从GB_table中删除了球员姓名和回合信息,我无法再了解预测是从谁/哪一回合进行的。

【问题讨论】:

    标签: python pandas machine-learning scikit-learn


    【解决方案1】:

    我假设您使用的是 pandas DataFrames,在这种情况下它非常简单。

    X_train 和 X_test DataFrames 中的索引号将对应于原始 'ds' DataFrame 中的索引。

    试试:

    pred = baseline.predict(X_test)
    pred_original_data = ds.iloc[X_test.index]
    pred_original_data['prediction'] = pred
    

    【讨论】:

      【解决方案2】:

      您可以在train_test_split 之后删除播放器列和其他字段。

      这是我的建议

      y = ds.isCaptain
      
      X_train, X_test, y_train, y_test = train_test_split(ds, y, test_size=0.2)
      
      baseline = GradientBoostingClassifier(learning_rate=0.01, n_estimators=1500,max_depth=4, min_samples_split=40, min_samples_leaf=7,max_features=4 , subsample=0.95, random_state=10)
      
      
      baseline.fit(X_train.drop(['Player', 'Round', 'isCaptain', 'Points'], axis=1),y_train)
      
      X_test_input = X_test.drop(['Player', 'Round', 'isCaptain', 'Points']
      score = baseline.score(X_test_input, y_test))
      print('Accuracy of GBM on test set: {:.3f}'.format(score)
      X_test['prediction'] = baseline.predict(X_test_input)
      print(classification_report(y_test, X_test['prediction']))
      

      【讨论】:

        猜你喜欢
        • 2018-11-23
        • 1970-01-01
        • 2018-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-29
        • 2012-10-11
        相关资源
        最近更新 更多