Exemplo n.º 1
0
    def test_multioutput_metrics(self):
        y_true = np.array([[1, 0, 0, 1], [0, 1, 1, 1], [1, 1, 0, 1]])
        y_pred = np.array([[0, 0, 0, 1], [1, 0, 1, 1], [0, 0, 0, 1]])
        assert_almost_equal(MSE(y_true, y_pred), [(1. / 3 + 2. / 3 + 2. / 3) / 4.])

        assert_almost_equal(MSLE(y_true, y_pred), [0.200], decimal=2)

        assert_almost_equal(MAE(y_true, y_pred), [(1. + 2. / 3) / 4.])

        assert_almost_equal(R2(y_true, y_pred, multioutput='variance_weighted'), [1. - 5. / 2])

        assert_almost_equal(R2(y_true, y_pred, multioutput='uniform_average'), [-.875])

        y_true = ([[3, -0.5, 2, 7], [3, -0.5, 2, 7], [3, -0.5, 2, 7]])
        y_pred = ([[2.5, -0.3, 2, 8], [2.5, -0.3, 2, 8], [2.5, -0.3, 2, 8]])

        assert_almost_equal(sMAPE(y_true, y_pred, multioutput='uniform_average'),
                            [10.19], decimal=2)
        assert_almost_equal(MAPE(y_true, y_pred, multioutput='uniform_average'), [17.74], decimal=2)
        assert_almost_equal(MPE(y_true, y_pred, multioutput='uniform_average'), [10.6], decimal=2)
        assert_almost_equal(RMSE(y_true, y_pred, multioutput='uniform_average'), [0.57], decimal=2)

        assert_almost_equal(ME(y_true, y_pred, multioutput='uniform_average'), [-0.18], decimal=2)
        assert_almost_equal(MSPE(y_true, y_pred, multioutput='uniform_average'), [0.32], decimal=2)
        assert_almost_equal(MDAPE(y_true, y_pred, multioutput='uniform_average'),
                            [17.74], decimal=2)
        assert_almost_equal(sMDAPE(y_true, y_pred, multioutput='uniform_average'),
                            [10.19], decimal=2)
Exemplo n.º 2
0
    def test_multioutput_array_metrics(self):
        y_true = [[1, 2], [2.5, -1], [4.5, 3], [5, 7]]
        y_pred = [[1, 1], [2, -1], [5, 4], [5, 6.5]]

        assert_array_almost_equal(MSE(y_true, y_pred, multioutput='raw_values'),
                                  [0.125, 0.5625], decimal=2)
        assert_array_almost_equal(MAE(y_true, y_pred, multioutput='raw_values'),
                                  [0.25, 0.625], decimal=2)
        assert_array_almost_equal(R2(y_true, y_pred, multioutput='raw_values'),
                                  [0.95, 0.93], decimal=2)

        assert_array_almost_equal(sMAPE(y_true, y_pred, multioutput='raw_values'),
                                  [4.09, 12.83], decimal=2)
        assert_array_almost_equal(MAPE(y_true, y_pred, multioutput='raw_values'),
                                  [7.78, 22.62], decimal=2)
        assert_array_almost_equal(MPE(y_true, y_pred, multioutput='raw_values'),
                                  [2.22, 5.95], decimal=2)
        assert_array_almost_equal(RMSE(y_true, y_pred, multioutput='raw_values'),
                                  [0.35, 0.75], decimal=2)

        assert_array_almost_equal(ME(y_true, y_pred, multioutput='raw_values'),
                                  [0., 0.12], decimal=2)
        assert_array_almost_equal(MSPE(y_true, y_pred, multioutput='raw_values'),
                                  [0.12, 0.56], decimal=2)
        assert_array_almost_equal(MDAPE(y_true, y_pred, multioutput='raw_values'),
                                  [5.56, 20.24], decimal=2)
        assert_array_almost_equal(sMDAPE(y_true, y_pred, multioutput='raw_values'),
                                  [2.63, 8.99], decimal=2)
Exemplo n.º 3
0
    def test_metrics(self, n_samples=50):
        y_true = np.arange(n_samples) + 1
        y_pred = y_true + 1

        assert_almost_equal(MSE(y_true, y_pred), [1.])
        assert_almost_equal(MSLE(y_true, y_pred),
                            MSE(np.log(1 + y_true), np.log(1 + y_pred)))
        assert_almost_equal(MAE(y_true, y_pred), [1.])
        assert_almost_equal(R2(y_true, y_pred), [0.995], 2)

        assert_almost_equal(sMAPE(y_true, y_pred), [3.89], decimal=2)

        y_true = [3, -0.5, 2, 7]
        y_pred = [2.5, -0.3, 2, 8]

        assert_almost_equal(MAPE(y_true, y_pred), [17.74], decimal=2)
        assert_almost_equal(MPE(y_true, y_pred), [10.6], decimal=2)
        assert_almost_equal(RMSE(y_true, y_pred), [0.57], decimal=2)
        assert_almost_equal(ME(y_true, y_pred), [-0.17], decimal=2)
        assert_almost_equal(MSPE(y_true, y_pred), [0.32], decimal=2)
        assert_almost_equal(MDAPE(y_true, y_pred), [15.48], decimal=2)
        assert_almost_equal(sMDAPE(y_true, y_pred), [7.88], decimal=2)