當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Tensorflow.js tf.metrics.recall()用法及代碼示例

Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。

tf.metrics.recall() 函數用於計算關於標簽的預測的召回率。 “召回”是機器學習的指標之一。你可以在這裏讀更多關於它的內容。

用法:

tf.metrics.recall (yTrue, yPred)

參數:

  • yTrue (tensor):它包含 0 或 1 的真值。
  • yPred (tensor):它隻包含 0 或 1 的預測值。

返回值:它返回一個張量(tf.tensor)。



範例1:

Javascript


const tf = require("@tensorflow/tfjs")
  
// Creating 2-D tensor of true values
const yTrue = tf.tensor2d([
    [0, 0, 1, 1],
    [0, 1, 0, 0],
    [0, 0, 0, 1]
]);
  
// Creating 2-D tensor of predicted values
const yPred = tf.tensor2d([
    [1, 0, 0, 1],
    [0, 1, 0, 0],
    [1, 0, 1, 1]
]);
  
// Getting the result from the recall function
const recallResult = tf.metrics.recall(yTrue, yPred);
recallResult.print();

輸出:

Tensor
   0.75

範例2:

Javascript


const tf = require("@tensorflow/tfjs")
  
// Creating 2-D tensor of true values
const trueValues = tf.tensor2d([
    [0, 0, 0],
    [1, 0, 0],
    [0, 1, 0]
]);
  
// Creating 2-D tensor of predicted values
const predValues = tf.tensor2d([
    [0, 1, 0],
    [0, 0, 1],
    [0, 1, 1]
]);
  
// Getting the result from the recall function
const recallResult = tf.metrics.recall(trueValues, predValues);
recallResult.print();

輸出:

Tensor
   0.5

參考: https://js.tensorflow.org/api/latest/#metrics.recall




相關用法


注:本文由純淨天空篩選整理自parasmadan15大神的英文原創作品 Tensorflow.js tf.metrics.recall() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。