使用分类模型进行预测
既然分类器已经拟合完成,接下来请用它来预测一些新采集花朵的类型(类别)。
多朵新花的花瓣宽度和长度信息已保存在变量 targets 中。请使用您拟合好的分类器,预测每朵花的类型。
本练习是课程的一部分
Python 中的时间序列机器学习
练习说明
- 使用数组
X_predict预测花的类型。 - 运行给定代码以可视化预测结果。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create input array
X_predict = targets[['petal length (cm)', 'petal width (cm)']]
# Predict with the model
predictions = ____
print(predictions)
# Visualize predictions and actual values
plt.scatter(X_predict['petal length (cm)'], X_predict['petal width (cm)'],
c=predictions, cmap=plt.cm.coolwarm)
plt.title("Predicted class values")
plt.show()