2016-04-26 21 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

相關問題