【问题标题】:How to join DecisionTreeRegressor predict output to the original data如何加入 DecisionTreeRegressor 预测输出到原始数据
【发布时间】:2016-08-19 14:07:47
【问题描述】:

我正在开发一个使用 DecisionTreeRegressor 的模型。我使用训练数据构建并拟合了树,并根据最近的数据预测了结果以确认模型的准确性。

构建和拟合树: X = np.matrix ( pre_x ) y = np.matrix(pre_y) regr_b = DecisionTreeRegressor(max_depth = 4) regr_b.fit(X, y)

预测新数据: X = np.matrix ( pre_test_x ) trial_pred = regr_b.predict(X, check_input=True)

trial_pred 是一个预测值数组。我需要将它加入到 pre_test_x 中,这样我才能看到预测与实际发生的情况有多匹配。

我尝试过合并:

all_pred = pre_pre_test_x.merge(predictions, left_index = True, right_index = True)

all_pred = pd.merge (pre_pre_test_x, predictions, how='left', left_index=True, right_index=True  )

要么没有结果,要么在所有现有列中附加到 DataFrame 底部的列的第二个副本,其中包含 NaN。

【问题讨论】:

    标签: join merge concat decision-tree predict


    【解决方案1】:

    事实证明这很简单。将预测输出保留为数组,然后运行: w_pred = pre_pre_test_x.copy(deep=True) w_pred['pred_val']=trial_pred

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-10
      • 2020-03-23
      • 1970-01-01
      • 2018-01-02
      相关资源
      最近更新 更多