开始使用免费开始使用

多分类任务的模型评估

在本练习中,您将使用 sklearn.metrics 模块来计算模型的评估指标。

模型已训练完毕,保存在变量 model 中。变量 X_testy_true 已加载,同时还导入了 sklearn.metrics 包中的函数 confusion_matrix()classification_report()

您将先计算模型的混淆矩阵。然后,为了汇总模型表现,您将使用 classification_report() 计算精确率(precision)、召回率(recall)和 F1-score。在该函数中,您可以选择将包含类别名称的 list(已存于变量 news_cat 中)传给参数 target_names,以便让报告更易读。

本练习是课程的一部分

使用 Keras 构建语言建模的循环神经网络(RNN)

查看课程

交互式实操练习

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

# Use the model to predict on new data
____ = model.____(X_test)

# Choose the class with higher probability 
y_pred = np.____(predicted, axis=1)
编辑并运行代码