可视化
可视化命令¶
通过使用 ludwig visualize
命令,可以从 train
、predict
和 experiment
的结果文件中获取几种可视化。该命令有几个参数,但并非所有可视化都使用所有参数。我们首先介绍通用脚本的参数,然后针对每种可用的可视化,讨论所需的特定参数及其生成的可视化类型。
usage: ludwig visualize [options]
This script analyzes results and shows some nice plots.
optional arguments:
-h, --help show this help message and exit
-g, --ground_truth GROUND_TRUTH
ground truth file
-gm, --ground_truth_metadata GROUND_TRUTH_METADATA
input metadata JSON file
-sf, --split_file SPLIT_FILE
file containing split values used in conjunction with
ground truth file.
-od, --output_directory OUTPUT_DIRECTORY
directory where to save plots. If not specified, plots
will be displayed in a window
-ff, --file_format {pdf,png}
file format of output plots
-v, --visualization {
binary_threshold_vs_metric,
calibration_1_vs_all,
calibration_multiclass,
compare_classifiers_multiclass_multimetric,
compare_classifiers_performance_changing_k,
compare_classifiers_performance_from_pred,
compare_classifiers_performance_from_prob
compare_classifiers_performance_subset,
compare_classifiers_predictions,
compare_classifiers_predictions_distribution,
compare_performance,confidence_thresholding,
confidence_thresholding_2thresholds_2d,
confidence_thresholding_2thresholds_3d,
confidence_thresholding_data_vs_acc,
confidence_thresholding_data_vs_acc_subset,
confidence_thresholding_data_vs_acc_subset_per_class,
confusion_matrix,
frequency_vs_f1,
hyperopt_hiplot,
hyperopt_report,
learning_curves,
roc_curves,
roc_curves_from_test_statistics
},
The type of visualization to generate
-ofn, --output_feature_name OUTPUT_FEATURE_NAME
name of the output feature to visualize
-gts, --ground_truth_split GROUND_TRUTH_SPLIT
ground truth split - 0:train, 1:validation, 2:test split
-tf, --threshold_output_feature_names THRESHOLD_OUTPUT_FEATURE_NAMES [THRESHOLD_OUTPUT_FEATURE_NAMES ...]
names of output features for 2d threshold
-pred, --predictions PREDICTIONS [PREDICTIONS ...]
predictions files
-prob, --probabilities PROBABILITIES [PROBABILITIES ...]
probabilities files
-trs, --training_statistics TRAINING_STATISTICS [TRAINING_STATISTICS ...]
training stats files
-tes, --test_statistics TEST_STATISTICS [TEST_STATISTICS ...]
test stats files
-hs, --hyperopt_stats_path HYPEROPT_STATS_PATH
hyperopt stats file
-mn, --model_names MODEL_NAMES [MODEL_NAMES ...]
names of the models to use as labels
-tn, --top_n_classes TOP_N_CLASSES [TOP_N_CLASSES ...]
number of classes to plot
-k, --top_k TOP_K
number of elements in the ranklist to consider
-ll, --labels_limit LABELS_LIMIT
maximum numbers of labels. Encoded numeric label values in
dataset that are higher than labels_limit are considered to
be "rare" labels
-ss, --subset {ground_truth,predictions}
type of subset filtering
-n, --normalize normalize rows in confusion matrix
-m, --metrics METRICS [METRICS ...]
metrics to dispay in threshold_vs_metric
-pl, --positive_label POSITIVE_LABEL
label of the positive class for the roc curve
-l, --logging_level {critical, error, warning, info, debug, notset}
the level of logging to use
参数的一些补充信息
- 列表参数都是对齐的。换句话说,
predictions
、probabilities
、training_statistics
、test_statistics
和model_names
是并行数组,model_names
的第 n 个条目应是对应于predictions
的第 n 个条目的模型的名称。 ground_truth
和ground_truth_metadata
分别是在训练预处理期间获取的HDF5
和JSON
文件。如果您计划使用可视化,训练时请勿使用--skip_save_preprocessing
参数。这些文件包含在预处理时执行的训练集/测试集划分。output_feature_name
是用于创建可视化的输出特征名称。
其他参数将为每种可视化详细说明,因为不同的可视化使用这些参数的方式不同。
示例¶
生成可视化示例命令是基于运行两个实验并比较它们。实验本身通过以下方式运行
ludwig experiment --experiment_name titanic --model_name Model1 --dataset train.csv -cf titanic_model1.yaml
ludwig experiment --experiment_name titanic --model_name Model2 --dataset train.csv -cf titanic_model2.yaml
要运行这些示例,您需要下载 Titanic Kaggle 竞赛数据集 以获取 train.csv
。请注意,下方与每种可视化相关的示例图片是使用不同数据集生成的。这两个模型使用 titanic_model1.yaml
定义
input_features:
-
name: Pclass
type: category
-
name: Sex
type: category
-
name: Age
type: number
preprocessing:
missing_value_strategy: fill_with_mean
-
name: SibSp
type: number
-
name: Parch
type: number
-
name: Fare
type: number
preprocessing:
missing_value_strategy: fill_with_mean
-
name: Embarked
type: category
output_features:
-
name: Survived
type: binary
并使用 titanic_model2.yaml
定义
input_features:
-
name: Pclass
type: category
-
name: Sex
type: category
-
name: SibSp
type: number
-
name: Parch
type: number
-
name: Embarked
type: category
output_features:
-
name: Survived
type: binary
学习曲线¶
learning_curves¶
此可视化的参数
output_directory
file_format
output_feature_name
training_statistics
model_names
对于每个模型(在 training_statistics
和 model_names
的对齐列表中)以及模型的每个输出特征和度量指标,它会生成一条线图,显示该度量指标在训练集和验证集上训练的 epoch 过程中如何变化。如果未指定 output_feature_name
,则绘制所有输出特征。
示例命令
ludwig visualize --visualization learning_curves \
--output_feature_name Survived \
--training_statistics results/titanic_Model1_0/training_statistics.json \
results/titanic_Model2_0/training_statistics.json \
--model_names Model1 Model2
混淆矩阵¶
confusion_matrix¶
此可视化的参数
ground_truth_metadata
output_directory
file_format
output_feature_name
test_statistics
model_names
top_n_classes
normalize
对于每个模型(在 test_statistics
和 model_names
的对齐列表中),它会为 test_statistics
中包含混淆矩阵的每个字段生成预测结果的混淆矩阵热图。top_n_classes
的值将热图限制为 n
个最常见的类别。
示例命令
ludwig visualize --visualization confusion_matrix \
--ground_truth_metadata results/titanic_Model1_0/model/train_set_metadata.json \
--test_statistics results/titanic_Model1_0/test_statistics.json \
--top_n_classes 2
生成的第二个图是条形图,显示每个类别的熵,按熵从高到低排名。
比较性能¶
compare_performance¶
此可视化的参数
output_directory
file_format
output_feature_name
test_statistics
model_names
对于每个模型(在 test_statistics
和 model_names
的对齐列表中),它会在条形图中生成条形,每个条形对应于指定 output_feature_name
的 test_statistics
文件中可用的一个整体指标。
示例命令
ludwig visualize --visualization compare_performance \
--output_feature_name Survived \
--test_statistics results/titanic_Model1_0/test_statistics.json \
results/titanic_Model2_0/test_statistics.json \
--model_names Model1 Model2
compare_classifiers_performance_from_prob¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
top_n_classes
labels_limit
output_feature_name
必须是类别特征的名称。对于每个模型(在 probabilities
和 model_names
的对齐列表中),它会在条形图中生成条形,每个条形对应于从指定 output_feature_name
的预测概率计算出的一个整体指标。
示例命令
ludwig visualize --visualization compare_classifiers_performance_from_prob \
--ground_truth train.hdf5 \
--output_feature_name Survived \
--probabilities results/titanic_Model1_0/Survived_probabilities.csv \
results/titanic_Model2_0/Survived_probabilities.csv \
--model_names Model1 Model2
compare_classifiers_performance_from_pred¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
predictions
model_names
labels_limit
output_feature_name
必须是类别特征的名称。对于每个模型(在 predictions
和 model_names
的对齐列表中),它会在条形图中生成条形,每个条形对应于从指定 output_feature_name
的预测结果即时计算出的一个整体指标。
示例命令
ludwig visualize --visualization compare_classifiers_performance_from_pred \
--ground_truth train.hdf5 \
--ground_truth_metadata train.json \
--output_feature_name Survived \
--predictions results/titanic_Model1_0/Survived_predictions.csv \
results/titanic_Model2_0/Survived_predictions.csv \
--model_names Model1 Model2
compare_classifiers_performance_subset¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
top_n_classes
labels_limit
subset
output_feature_name
必须是类别特征的名称。对于每个模型(在 predictions
和 model_names
的对齐列表中),它会在条形图中生成条形,每个条形对应于从指定 output_feature_name
的概率预测结果即时计算出的一个整体指标,仅考虑完整训练集的一个子集。获取子集的方式是使用 top_n_classes
和 subset
参数。
如果 subset
的值为 ground_truth
,则只有真实类别属于前 n
个最常见类别的那些数据点才会被视为测试集,并将显示从原始集合中保留的数据点百分比。
示例命令
ludwig visualize --visualization compare_classifiers_performance_subset \
--ground_truth train.hdf5 \
--ground_truth_metadata train.json \
--output_feature_name Survived \
--probabilities results/titanic_Model1_0/Survived_probabilities.csv \
results/titanic_Model2_0/Survived_probabilities.csv \
--model_names Model1 Model2 \
--top_n_classes 2 \
--subset ground_truth
如果 subset
的值为 predictions
,则只有模型预测类别属于前 n
个最常见类别的那些数据点才会被视为测试集,并将显示为每个模型从原始集合中保留的数据点百分比。
compare_classifiers_performance_changing_k¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
top_k
labels_limit
output_feature_name
必须是类别特征的名称。对于每个模型(在 probabilities
和 model_names
的对齐列表中),它会生成一条线图,显示 Hits@K 指标(如果模型在排名前 k
的预测中包含真实类别,则视为正确预测)在指定 output_feature_name
上随着 k
从 1 变化到 top_k
的情况。
示例命令
ludwig visualize --visualization compare_classifiers_performance_changing_k \
--ground_truth train.hdf5 \
--output_feature_name Survived \
--probabilities results/titanic_Model1_0/Survived_probabilities.csv \
results/titanic_Model2_0/Survived_probabilities.csv \
--model_names Model1 Model2 \
--top_k 5
compare_classifiers_multiclass_multimetric¶
此可视化的参数
ground_truth_metadata
output_directory
file_format
output_feature_name
test_statistics
model_names
top_n_classes
output_feature_name
必须是类别特征的名称。对于每个模型(在 test_statistics
和 model_names
的对齐列表中),它会生成四个图,显示模型在指定 output_feature_name
上针对多个类别的精确率、召回率和 F1 分数。
第一个图显示模型在前 n
个最常见类别上的指标。
第二个图显示模型在前 n
个表现最佳类别上的指标。
第三个图显示模型在前 n
个表现最差类别上的指标。
第四个图显示模型在所有类别上的指标,按类别频率排序。如果类别数量过多,此图将难以阅读。
比较分类器预测结果¶
compare_classifiers_predictions¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
predictions
model_names
labels_limit
output_feature_name
必须是类别特征的名称,并且必须只有两个模型(在 predictions
和 model_names
的对齐列表中)。此可视化生成一个饼图,比较这两个模型对指定 output_feature_name
的预测结果。
示例命令
ludwig visualize --visualization compare_classifiers_predictions \
--ground_truth train.hdf5 \
--output_feature_name Survived \
--predictions results/titanic_Model1_0/Survived_predictions.csv \
results/titanic_Model2_0/Survived_predictions.csv \
--model_names Model1 Model2
compare_classifiers_predictions_distribution¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
predictions
model_names
labels_limit
output_feature_name
必须是类别特征的名称。此可视化生成一个雷达图,比较模型对指定 output_feature_name
前 10 个类别的预测分布。
置信度阈值设置¶
confidence_thresholding¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
labels_limit
output_feature_name
必须是类别特征的名称。对于每个模型(在 probabilities
和 model_names
的对齐列表中),它会生成一对线条,指示模型准确率和数据覆盖率随指定 output_feature_name
的预测概率阈值增加(x 轴)的变化。
confidence_thresholding_data_vs_acc¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
labels_limit
output_feature_name
必须是类别特征的名称。对于每个模型(在 probabilities
和 model_names
的对齐列表中),它会生成一条线,指示模型准确率和数据覆盖率随指定 output_feature_name
的预测概率阈值增加的变化。与 confidence_thresholding
的区别在于它使用两个轴而不是三个轴,不显示阈值,并且将覆盖率作为 x 轴而不是阈值。
confidence_thresholding_data_vs_acc_subset¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
top_n_classes
labels_limit
subset
output_feature_name
必须是类别特征的名称。对于每个模型(在 probabilities
和 model_names
的对齐列表中),它会生成一条线,指示模型准确率和数据覆盖率随指定 output_feature_name
的预测概率阈值增加的变化,仅考虑完整训练集的一个子集。获取子集的方式是使用 top_n_classes
和 subset
参数。与 confidence_thresholding
的区别在于它使用两个轴而不是三个轴,不显示阈值,并且将覆盖率作为 x 轴而不是阈值。
如果 subset
的值为 ground_truth
,则只有真实类别属于前 n
个最常见类别的那些数据点才会被视为测试集,并将显示从原始集合中保留的数据点百分比。如果 subset
的值为 predictions
,则只有模型预测类别属于前 n
个最常见类别的那些数据点才会被视为测试集,并将显示为每个模型从原始集合中保留的数据点百分比。
confidence_thresholding_data_vs_acc_subset_per_class¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
top_n_classes
labels_limit
subset
output_feature_name
必须是类别特征的名称。对于每个模型(在 probabilities
和 model_names
的对齐列表中),它会生成一条线,指示模型准确率和数据覆盖率随指定 output_feature_name
的预测概率阈值增加的变化,仅考虑完整训练集的一个子集。获取子集的方式是使用 top_n_classes
和 subset
参数。与 confidence_thresholding
的区别在于它使用两个轴而不是三个轴,不显示阈值,并且将覆盖率作为 x 轴而不是阈值。
如果 subset
的值为 ground_truth
,则只有真实类别属于前 n
个最常见类别的那些数据点才会被视为测试集,并将显示从原始集合中保留的数据点百分比。如果 subset
的值为 predictions
,则只有模型预测类别属于前 n
个最常见类别的那些数据点才会被视为测试集,并将显示为每个模型从原始集合中保留的数据点百分比。
与 confidence_thresholding_data_vs_acc_subset
的区别在于它会为 top_n_classes
中的每个类别生成一个图。
confidence_thresholding_2thresholds_2d¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
ground_truth_split
threshold_output_feature_names
probabilities
model_names
labels_limit
threshold_output_feature_names
必须正好是两个,可以是类别或二元特征。probabilities
必须正好是两个,与 threshold_output_feature_names
对齐。model_names
必须正好是一个。将生成三个图。
第一个图显示了几条半透明线条。它们总结了 confidence_thresholding_2thresholds_3d
显示的 3D 曲面,该曲面以两个 threshold_output_feature_names
的预测置信度阈值作为 x 轴和 y 轴,以数据覆盖率百分比或准确率作为 z 轴。每条线表示数据覆盖曲面投影到准确率曲面上的一个切片。
第二个图显示第一个图中显示的所有线条的最大值。
第三个图显示最大值线以及获得特定数据覆盖率与准确率值对的阈值。
confidence_thresholding_2thresholds_3d¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
ground_truth_split
threshold_output_feature_names
probabilities
labels_limit
threshold_output_feature_names
必须正好是两个,可以是类别或二元特征。probabilities
必须正好是两个,与 threshold_output_feature_names
对齐。该图显示了 confidence_thresholding_2thresholds_3d
显示的 3D 曲面,该曲面以两个 threshold_output_feature_names
的预测置信度阈值作为 x 轴和 y 轴,以数据覆盖率百分比或准确率作为 z 轴。
二进制阈值对比指标¶
binary_threshold_vs_metric¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
metrics
positive_label
output_feature_name
可以是类别或二元特征。对于 metrics
中指定的每个指标(选项包括 f1
、precision
、recall
、accuracy
),此可视化生成一个折线图,绘制模型置信度阈值与指定 output_feature_name
的指标之间的关系。如果 output_feature_name
是类别特征,positive_label
指示哪个类别被视为正类别,所有其他类别将被视为负类别。positive_label
必须是整数,要查找与类别关联的整数标签,请检查 ground_truth_metadata
JSON 文件。
ROC 曲线¶
roc_curves¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
positive_label
output_feature_name
可以是类别或二元特征。此可视化生成一个折线图,绘制指定 output_feature_name
的 ROC 曲线。如果 output_feature_name
是类别特征,positive_label
指示哪个类别被视为正类别,所有其他类别将被视为负类别。positive_label
必须是整数,要查找与类别关联的整数标签,请检查 ground_truth_metadata
JSON 文件。
roc_curves_from_test_statistics¶
此可视化的参数
output_directory
file_format
output_feature_name
test_statistics
model_names
output_feature_name
必须是二元特征的名称。此可视化生成一个折线图,绘制指定 output_feature_name
的 ROC 曲线。
精确率-召回率曲线¶
precision_recall_curves¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
positive_label
output_feature_name
可以是类别或二元特征。此可视化生成一个折线图,绘制指定 output_feature_name
的精确率-召回率曲线。如果 output_feature_name
是类别特征,positive_label
指示哪个类别被视为正类别,所有其他类别将被视为负类别。positive_label
必须是整数,要查找与类别关联的整数标签,请检查 ground_truth_metadata
JSON 文件。
precision_recall_curves_from_test_statistics¶
此可视化的参数
output_directory
file_format
output_feature_name
test_statistics
model_names
output_feature_name
必须是二元特征的名称。此可视化生成一个折线图,绘制指定 output_feature_name
的精确率-召回率曲线。
校准图¶
calibration_1_vs_all¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
top_n_classes
labels_limit
output_feature_name
必须是类别或二元特征的名称。对于每个类别或(如果指定了 top_n_classes
则为)前 n
个最常见类别中的每个类别,它会生成两个图,这些图根据指定 output_feature_name
的预测概率计算得出。
第一个图是一个校准曲线,显示将当前类别视为真实类别、其他类别视为错误类别时的预测校准情况,为每个模型(在 probabilities
和 model_names
的对齐列表中)绘制一条线。
第二个图显示将当前类别视为真实类别、其他类别视为错误类别时的预测分布,为每个模型(在 probabilities
和 model_names
的对齐列表中)绘制分布。
calibration_multiclass¶
此可视化的参数
ground_truth
split_file
ground_truth_metadata
output_directory
file_format
output_feature_name
ground_truth_split
probabilities
model_names
labels_limit
output_feature_name
必须是类别特征的名称。对于每个类别,会生成两个图,这些图根据指定 output_feature_name
的预测概率计算得出。
第一个图是一个校准曲线,显示考虑所有类别时的预测校准情况,为每个模型(在 probabilities
和 model_names
的对齐列表中)绘制一条线。
第二个图显示一个条形图,显示 Brier 分数(用于计算模型预测概率的校准程度),为每个模型(在 probabilities
和 model_names
的对齐列表中)绘制一个条形。
类别频率对比 F1 分数¶
frequency_vs_f1¶
此可视化的参数
ground_truth_metadata
output_directory
file_format
output_feature_name
test_statistics
model_names
top_n_classes
output_feature_name
必须是类别特征的名称。对于每个模型(在 test_statistics
和 model_names
的对齐列表中),会生成两个图,显示指定 output_feature_name
的预测统计信息。
为 top_n_classes
生成图。第一个图是折线图,其中一个 x 轴代表不同的类别,两个垂直轴分别用橙色和蓝色着色。橙色轴表示类别的频率,并绘制一条橙色线显示趋势。蓝色轴表示该类别的 F1 分数,并绘制一条蓝色线显示趋势。x 轴上的类别按 F1 分数排序。
第二个图的结构与第一个图相同,但轴翻转了,x 轴上的类别按频率排序。
超参数优化可视化¶
此处显示的超参数可视化示例是通过在用于根据用户话语对意图进行分类的 ATIS 数据集 上运行包含 100 个样本的随机搜索获得的。
hyperopt_report¶
此可视化的参数
output_directory
file_format
hyperopt_stats_path
此可视化为 hyperopt_stats_path
文件中的每个超参数(例如,损失)与 Hyperopt 优化的指标之间的关系创建一个图,外加一个显示超参数交互的对图。
每个图将显示参数相对于待优化指标的分布。对于 float
和 int
参数使用散点图,而对于 category
参数使用 Raincloud 图。Raincloud 图可以可视化原始数据、概率密度以及中位数、均值和相关置信区间等关键摘要统计数据,同时具有最小的冗余。
浮点参数 Hyperopt 图¶
整数参数 Hyperopt 图¶
类别参数 Hyperopt 图¶
注意
对于 category
类型的参数,只有在训练了足够的 Hyperopt 试验,使得每个参数值至少有 2 个或更多试验时,才会创建 Raincloud 图。否则,将创建 stripplot(一种类别散点图)。
对图显示了超参数对的值与待优化指标之间相关性的热图。
hyperopt_hiplot¶
此可视化的参数
output_directory
file_format
hyperopt_stats_path
此可视化使用平行坐标图一次性可视化超参数优化的所有结果,生成一个交互式 HTML 页面。
注意
只有当 Hyperopt 参数空间中存在多个参数时,才会创建此图。
Tensorboard¶
用户可以使用 Tensorboard 可视化原始训练指标
tensorboard --logdir </path/to/model>/log