根據預測和標簽計算混淆矩陣。
用法
tf.compat.v1.confusion_matrix(
labels, predictions, num_classes=None, dtype=tf.dtypes.int32, name=None,
weights=None
)
參數
-
labels
用於分類任務的真實標簽的 1-DTensor
。 -
predictions
給定分類的一維Tensor
預測。 -
num_classes
分類任務可能具有的標簽數量。如果未提供此值,則將使用預測和標簽數組進行計算。 -
dtype
混淆矩陣的數據類型。 -
name
範圍名稱。 -
weights
一個可選的Tensor
,其形狀匹配predictions
。
返回
-
dtype
類型的Tensor
形狀為[n, n]
表示混淆矩陣,其中n
是分類任務中可能的標簽數。
拋出
-
ValueError
如果預測和標簽都不是一維向量並且形狀不匹配,或者如果weights
不是None
並且其形狀不匹配predictions
。
矩陣列代表預測標簽,行代表真實標簽。混淆矩陣始終是形狀為 [n, n]
的二維數組,其中 n
是給定分類任務的有效標簽數。預測和標簽都必須是相同形狀的一維數組,才能使該函數起作用。
如果 num_classes
是 None
,則 num_classes
將設置為預測或標簽中的最大值加一。類標簽應從 0 開始。例如,如果 num_classes
為 3,則可能的標簽將是 [0, 1, 2]
。
如果 weights
不是 None
,則每個預測都將其相應的權重貢獻給混淆矩陣單元的總值。
例如:
tf.math.confusion_matrix([1, 2, 4], [2, 2, 4]) ==>
[[0 0 0 0 0]
[0 0 1 0 0]
[0 0 1 0 0]
[0 0 0 0 0]
[0 0 0 0 1]]
請注意,可能的標簽假定為 [0, 1, 2, 3, 4]
,從而產生 5x5 混淆矩陣。
相關用法
- Python tf.compat.v1.convert_to_tensor用法及代碼示例
- Python tf.compat.v1.cond用法及代碼示例
- Python tf.compat.v1.constant用法及代碼示例
- Python tf.compat.v1.count_nonzero用法及代碼示例
- Python tf.compat.v1.case用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.compat.v1.strings.length用法及代碼示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代碼示例
- Python tf.compat.v1.feature_column.categorical_column_with_vocabulary_file用法及代碼示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代碼示例
- Python tf.compat.v1.variable_scope用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.as_numpy_iterator用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.covariance用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.confusion_matrix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。