2016-04-26 92 views
1

我正在开发一个使用DecisionTreeRegressor的模型。我使用训练数据构建并拟合了树,并预测了来自更新近数据的结果以确认模型的准确性。如何加入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 =真)

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 ) 

,要么没有结果或在所有现有列追加到数据框的底部,楠列的第二个副本。

回答

1

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