【问题标题】:What is model.predict(x.head) really predicting when using DecisionTreeRegressor from sklearn.tree?使用 sklearn.tree 中的 DecisionTreeRegressor 时,model.predict(x.head) 真正预测的是什么?
【发布时间】:2021-06-17 19:49:43
【问题描述】:

我使用来自 scikit-learn DecisionTreeRegressor 的predict 尝试对一些疯狂三月的统计数据进行建模,但我真的不知道我的结果意味着什么。

predict 函数预测什么?它是对列中接下来的内容的估计还是像矩阵一样解决它?

from sklearn.tree import DecisionTreeRegressor

model = DecisionTreeRegressor(random_state=1)
model.fit(x, y)

#file_path_test = '/content/sample_data/MM_Prediction_21 - Sheet5.csv'
data_test = pd.read_csv(file_path)
x1 = data_test[features]

print(model.predict(x1.head()))

【问题讨论】:

  • predict 函数预测什么,预测给定数据的标签或值。
  • 一个 ML 模型从您在训练期间给他的示例 X_train 和 y_train 中“学习”,并尝试从中构建模型。然后它将模型应用于您提供的新 X_new 并要求他预测 y_new 值。
  • 好的,那么当您尝试阅读文档时发生了什么?您对机器学习有任何背景了解吗?

标签: python machine-learning scikit-learn decision-tree


【解决方案1】:

model.predict 使用上面拟合的模型根据特征预测值。在这种特定情况下,它是一个DecisionTreeClassifier,它构建了一个Decision Tree。在预测阶段,构建的树用于预测每个特征向量落在哪个叶子节点上,并输出该叶子节点中的类标签。

【讨论】:

    猜你喜欢
    • 2014-09-20
    • 1970-01-01
    • 2019-09-07
    • 2015-02-28
    • 2019-09-20
    • 2021-07-12
    • 2022-12-04
    • 2018-02-14
    • 1970-01-01
    相关资源
    最近更新 更多