Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
Add regression diagnotic calcs #70
Browse files Browse the repository at this point in the history
  • Loading branch information
ceholden committed Dec 6, 2015
1 parent 3004076 commit df582d2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/regression/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import os

import numpy as np
import pandas as pd
import pytest

here = os.path.dirname(__file__)


@pytest.fixture(scope='function')
def prng():
return np.random.RandomState(123456789)


@pytest.fixture(scope='function')
def airquality(request):
airquality = pd.read_csv(os.path.join(here, 'data', 'airquality.csv'))
Expand Down
18 changes: 18 additions & 0 deletions tests/regression/test_regression_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import pytest

from yatsm.regression.diagnostics import rmse

n = 500


@pytest.fixture
def y(prng):
y = prng.standard_normal(n)
return y


def test_rmse(y):
yhat = y + 1.0
_rmse = rmse(y, yhat)
np.testing.assert_allclose(_rmse, 1.0)
22 changes: 22 additions & 0 deletions yatsm/regression/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
""" Regression diagnostics calculations
Includes:
- rmse: calculate root mean squared error
"""
import numpy as np

from ..accel import try_jit


@try_jit(nopython=True)
def rmse(y, yhat):
""" Calculate and return Root Mean Squared Error (RMSE)
Args:
y (np.ndarray): known values
yhat (np.ndarray): predicted values
Returns:
float: Root Mean Squared Error
"""
return ((y - yhat) ** 2).mean() ** 0.5

0 comments on commit df582d2

Please sign in to comment.