API - Metrics¶
The tensorlayerx.metrics directory contians Accuracy, Auc, Precision and Recall. For more complex metrics, you can encapsulates metric logic and APIs by base class.
Metric list¶
|
Base class for metric |
|
Accuracy metric |
|
The auc metric is for binary classification. |
Precision score for binary classification task. |
|
|
Recall score for binary classification task. |
|
Accuracy function. |
Metric¶
Accuracy¶
-
class
tensorlayerx.metrics.
Accuracy
(topk=1)[source]¶ Accuracy metric
- Parameters:
topk (int) – Specifies the top-k categorical accuracy to compute. Default is (1,).
Examples
>>> import tensorlayerx as tlx >>> y_pred = tlx.ops.convert_to_tensor(np.array([[0.3, 0.2, 0.1, 0.4], [0.2, 0.2, 0.5, 0.1]])) >>> y_true = tlx.ops.convert_to_tensor(np.array([[1], [3]])) >>> metric = tlx.metrics.Accuracy() >>> metric.update(y_pred, y_true) >>> res = metric.result() >>> metric.reset()
Auc¶
-
class
tensorlayerx.metrics.
Auc
(curve='ROC', num_thresholds=4095)[source]¶ The auc metric is for binary classification.
- Parameters:
curve (str) – Specifies the mode of the curve to be computed. Only support ‘ROC’ now.
num_thresholds (int) – The number of thresholds to use when discretizing the roc curve.
Precision¶
-
class
tensorlayerx.metrics.
Precision
[source]¶ Precision score for binary classification task.
Examples
>>> import tensorlayerx as tlx >>> y_pred = tlx.ops.convert_to_tensor(np.array([0.3, 0.2, 0.1, 0.7])) >>> y_true = tlx.ops.convert_to_tensor(np.array([1, 0, 0, 1])) >>> metric = tlx.metrics.Precision() >>> metric.update(y_pred, y_true) >>> res = metric.result() >>> metric.reset()
Recall¶
-
class
tensorlayerx.metrics.
Recall
[source]¶ Recall score for binary classification task.
Examples
>>> import tensorlayerx as tlx >>> y_pred = tlx.ops.convert_to_tensor(np.array([0.3, 0.2, 0.1, 0.7])) >>> y_true = tlx.ops.convert_to_tensor(np.array([1, 0, 0, 1])) >>> metric = tlx.metrics.Recall() >>> metric.update(y_pred, y_true) >>> res = metric.result() >>> metric.reset()
acc¶
-
tensorlayerx.metrics.
acc
(predicts, labels, topk=1)[source]¶ Accuracy function.
- Parameters:
predicts (Tensor) – The predicted value.
labels (Tensor) – The ground truth.
topk (int) – The top k predictions for each class will be checked.
- Returns:
- Return type:
The accuracy result.
Examples
>>> import tensorlayerx as tlx >>> y_pred = tlx.ops.convert_to_tensor(np.array([[0.3, 0.2, 0.1, 0.4], [0.2, 0.2, 0.5, 0.1]])) >>> y_true = tlx.ops.convert_to_tensor(np.array([[1], [3]])) >>> acc = tlx.metrics.acc(y_pred, y_true, topk=1)