【发布时间】: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