29
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

予測精度評価指標をPythonで実装する

Last updated at Posted at 2019-03-01

構築したアルゴリズムの予測結果を評価するための誤差について

以下の誤差を紹介します。

略称 日本語
Mean Absolute Error MAE 平均絶対誤差
Mean Absolute Persentage Error MAPE 平均絶対誤差率
Root Mean Squared Error RMSE 平均平方二乗誤差
Root Mean Squared Persentage Error RMSPE 平均平方二乗誤差率

Mean Absolute Error

基本。

\dfrac {1}{N} \sum ^{N}_{i=1}\left| \widehat {y_{i}}- y_{i}\right|
from sklearn.metrics import mean_absolute_error
mean_absolute_error(true, pred)

Mean Absolute Persentage Error

異なるスケール間の誤差を比較できる。

\dfrac {100}{N}\sum ^{N}_{i=1}\left| \frac{ \widehat {y_{i}}-y_{i} }{y_{i}}\right|
import numpy as np
np.mean(np.abs((pred - true) / true)) * 100

Root Mean Squared Error

MAEに比べ誤差の影響が大きい。

\left(\dfrac {1}{N}\sum ^{N}_{i=1}\left( \widehat {y_{i}}-y_{i} \right)^2\right)^{\frac{1}{2}}
import numpy as np
from sklearn.metrics import mean_squared_error
np.sqrt(mean_squared_error(true, pred))

Root Mean Squared Persentage Error

誤差の影響を大きく反映し、かつ異なるスケール間の誤差を比較できる。

100\left(\dfrac {1}{N}\sum ^{N}_{i=1}\left( \frac{\widehat {y_{i}}- y_{i} }{y_{i}}\right)^2\right)^{\frac{1}{2}} 
import numpy as np
np.sqrt(np.mean(((pred - true) / true)**2))*100

これすごい

手書きの式をTeX式にしてくれます。
https://webdemo.myscript.com/views/math/index.html

29
30
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?