开始使用免费开始使用

构建 Decision Tree

现在您已经将航班数据拆分为训练集和测试集,可以用训练集来拟合一个 Decision Tree 模型。

数据分别存为 flights_trainflights_test

注意:模型训练需要几秒钟……请耐心等待!

本练习是课程的一部分

使用 PySpark 进行机器学习

查看课程

练习说明

  • 导入用于创建 Decision Tree 分类器的类。
  • 创建一个分类器对象,并将其拟合到训练数据上。
  • 对测试数据进行预测,并查看预测结果。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import the Decision Tree Classifier class
from pyspark.ml.____ import ____

# Create a classifier object and fit to the training data
tree = ____()
tree_model = tree.____(____)

# Create predictions for the testing data and take a look at the predictions
prediction = tree_model.____(____)
prediction.select('label', 'prediction', 'probability').show(5, False)
编辑并运行代码