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


R yardstick smape 對稱平均絕對百分比誤差

計算對稱平均絕對百分比誤差。該指標采用相對單位。

用法

smape(data, ...)

# S3 method for data.frame
smape(data, truth, estimate, na_rm = TRUE, case_weights = NULL, ...)

smape_vec(truth, estimate, na_rm = TRUE, case_weights = NULL, ...)

參數

data

data.frame 包含由 truthestimate 參數指定的列。

...

目前未使用。

truth

真實結果的列標識符(即 numeric )。這應該是一個不帶引號的列名,盡管此參數是通過表達式傳遞的並且支持quasiquotation(您可以不帶引號的列名)。對於 _vec() 函數,一個 numeric 向量。

estimate

預測結果的列標識符(也是 numeric )。與 truth 一樣,可以通過不同的方式指定,但主要方法是使用不帶引號的變量名稱。對於 _vec() 函數,一個 numeric 向量。

na_rm

logical 值,指示在計算繼續之前是否應剝離 NA 值。

case_weights

案例權重的可選列標識符。這應該是一個不帶引號的列名稱,其計算結果為 data 中的數字列。對於 _vec() 函數,一個數值向量。

tibble 包含列 .metric.estimator.estimate 以及 1 行值。

對於分組 DataFrame ,返回的行數將與組數相同。

對於 smape_vec() ,單個 numeric 值(或 NA )。

細節

smape() 的此實現是 "usual definition",其中分母除以 2。

也可以看看

其他數字指標:ccc() , huber_loss_pseudo() , huber_loss() , iic() , mae() , mape() , mase() , mpe() , msd() , poisson_log_loss() , rmse() , rpd() , rpiq() , rsq_trad() , rsq()

其他準確度指標:ccc() , huber_loss_pseudo() , huber_loss() , iic() , mae() , mape() , mase() , mpe() , msd() , poisson_log_loss() , rmse()

作者

馬克斯·庫恩、裏亞茲·赫達亞蒂

例子

# Supply truth and predictions as bare column names
smape(solubility_test, solubility, prediction)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 smape   standard        36.7

library(dplyr)

set.seed(1234)
size <- 100
times <- 10

# create 10 resamples
solubility_resampled <- bind_rows(
  replicate(
    n = times,
    expr = sample_n(solubility_test, size, replace = TRUE),
    simplify = FALSE
  ),
  .id = "resample"
)

# Compute the metric by group
metric_results <- solubility_resampled %>%
  group_by(resample) %>%
  smape(solubility, prediction)

metric_results
#> # A tibble: 10 × 4
#>    resample .metric .estimator .estimate
#>    <chr>    <chr>   <chr>          <dbl>
#>  1 1        smape   standard        33.5
#>  2 10       smape   standard        28.9
#>  3 2        smape   standard        41.6
#>  4 3        smape   standard        28.4
#>  5 4        smape   standard        37.0
#>  6 5        smape   standard        31.8
#>  7 6        smape   standard        48.3
#>  8 7        smape   standard        27.8
#>  9 8        smape   standard        35.6
#> 10 9        smape   standard        30.2

# Resampled mean estimate
metric_results %>%
  summarise(avg_estimate = mean(.estimate))
#> # A tibble: 1 × 1
#>   avg_estimate
#>          <dbl>
#> 1         34.3
源代碼:R/num-smape.R

相關用法


注:本文由純淨天空篩選整理自Max Kuhn等大神的英文原創作品 Symmetric mean absolute percentage error。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。