コンテンツにスキップ

sensorutils.metrics

Note

可能ならsklearn.metricsを使用したほうが良い


mae(true, pred, axis=None)

Calc Mean Absolute Error.

\[ \frac{1}{N}\sum_{i=0}^{N} |\hat{y}_i - y_i| \]

Parameters:

Name Type Description Default
true ndarray

true data.

required
pred ndarray

predicted data.

required

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> mae(a, b)
>>> mae(a, b, axis=2)

Returns:

Type Description
Union[float, numpy.ndarray]

MAE


mape(true, pred, axis=None)

Calc Mean Absolute Persentage Error.

\[ \frac{100}{N}\sum_{i=0}^{N} \left| \frac{\hat{y}_i - y_i}{y_i} \right| \]

Parameters:

Name Type Description Default
true ndarray

true data.

required
pred ndarray

predicted data.

required

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> mape(a, b)
>>> mape(a, b, axis=2)

Returns:

Type Description
Union[float, numpy.ndarray]

MAPE


mse(true, pred, axis=None)

Calc Mean Squared Error.

\[ \frac{1}{N}\sum_{i=0}^{N} (dst_i - src_i)^2 \]

Parameters:

Name Type Description Default
true ndarray

true data.

required
pred ndarray

predicted data.

required

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> mse(a, b)
>>> mse(a, b, axis=2)

Returns:

Type Description
Union[float, numpy.ndarray]

MSE


rmse(true, pred, axis=None)

Calc Root Mean Squared Error.

\[ \left(\frac{1}{N}\sum_{i=0}^{N} (\hat{y}_i - y_i)^2 \right)^{\frac{1}{2}} \]

Parameters:

Name Type Description Default
true ndarray

true data.

required
pred ndarray

predicted data.

required

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> rmse(a, b)
>>> rmse(a, b, axis=2)

Returns:

Type Description
Union[float, numpy.ndarray]

RMSE


rmspe(true, pred, axis=None)

Calc Root Mean Squared Persentage Error.

\[ 100 \left(\frac{1}{N}\sum_{i=0}^{N} (\frac{\hat{y}_i - y_i}{y_i})^2 \right)^{\frac{1}{2}} \]

Parameters:

Name Type Description Default
true ndarray

true data.

required
pred ndarray

predicted data.

required

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> rmspe(a, b)
>>> rmspe(a, b, axis=2)

Returns:

Type Description
Union[float, numpy.ndarray]

RMSPE


rmsle(true, pred, axis=None)

Calc root mean squared logarithmic error.

\[ \left(\frac{1}{N}\sum_{i=0}^{N} (\log (\hat{y}_i + 1) - \log (y_i + 1))^2 \right)^{\frac{1}{2}} \]

Parameters:

Name Type Description Default
true ndarray

clean data

required
pred ndarray

with noise

required
axis Optional[int]

mean axis

None

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> rmsle(a, b)
>>> rmsle(a, b, axis=2)

Returns:

Type Description
Union[float, numpy.ndarray]

RMSLE


r2(true, pred)

Calc r2 score(coefficient of determination).

\[ {R^{2}}( \hat{y} ) := 1 - \frac{ \frac{1}{N} \sum_{i=1}^{N} { ( {y}_i - \hat{y}_{i} ) }^{2} }{ \frac{1}{N} \sum_{i=1}^{N} { ( {y}_i - \bar{y}) }^{2} } = 1 - \frac{M S E(\hat{y})}{Var(y)} \]

Parameters:

Name Type Description Default
true ndarray

clean data

required
pred ndarray

with noise

required

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> r2(a, b)

Returns:

Type Description
float

coefficient of determination


snr(true, pred, axis=None)

Calc Signal to Noise Ratio.

\[ 10 \log_{10} \left(\frac{\sum_{i=0}^{N}true_i^2}{\sum_{i=0}^{N}(true_i - pred_i)^2} \right) \]

Parameters:

Name Type Description Default
true ndarray

clean data

required
pred ndarray

with noise

required
axis Optional[int]

mean axis (default=None)

None

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> snr(a, b)
>>> snr(a, b, axis=2)

Returns:

Type Description
Union[float, numpy.ndarray]

SNR


lsd(true_spec, pred_spec, axis=None)

Calc Log Spectral Distance.

\[ \mathrm{LSD}(S(\omega),\tilde{S}(\omega)) = \sqrt{\frac{1}{W}\sum_{\omega}^{W} \left(20\log_{10}\left|\frac{S(\omega)}{\tilde{S}(\omega)}\right|\right)^2} \]

\(S(\omega)\)\(\tilde{S}(\omega)\) は,それぞれ原波形と雑音抑圧波形の対数スペクトル.

複数の短時間スペクトルの距離は各スペクトルで距離を算出した後,平均を取ること.

Parameters:

Name Type Description Default
true_spec ndarray

spectral 1

required
pred_spec ndarray

spectral 2

required
axis Optional[int]

Not use

None

Examples:

>>> a = np.random.randn(2, 3, 4)
>>> b = np.random.randn(2, 3, 4)
>>> lsd(a, b).shape

Returns:

Type Description
Union[float, numpy.ndarray]

LSD