2017-08-02 43 views
0

假設我們要更改Abalone regression example,以便有額外的評估指標。該指標,叫做pctWrong,等於預測的,其誤差爲> 1%的百分比: === pseudocode === pctWrong = countTrue(if (|y-y_hat|/y > 1%) True else False)/countTotalTensorflow:自定義錯誤聚合器

=== Python === 
105 # Calculate additional eval metrics 
106 eval_metric_ops = { 
107  "rmse": tf.metrics.root_mean_squared_error(
108   tf.cast(labels, tf.float64), predictions), 
109  "pctWrong": ??? 
110 } 

你會如何定義這樣的指標?我發現tf.metrics.percentage_below(),這可能會有幫助,但我不知道如何使用它。特別是我不知道如何獲得它的values參數。

回答

0

更新:畢竟這並不難。下面的代碼有點粗糙,但它的工作原理。

# Calculate additional eval metrics 
ys = tf.cast(labels, tf.float64) 
y_hats = predictions 
losses = tf.divide(tf.abs(tf.subtract(ys, y_hats)), ys) 
accuracies = -losses 

eval_metric_ops = { 
    "rmse": tf.metrics.root_mean_squared_error(tf.cast(labels, tf.float64), predictions), 
    "pctWrong": tf.metrics.percentage_below(accuracies, -0.01) 
}