Skip to content

Commit

Permalink
Tests for fit_model and predict.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiffyclub committed Apr 10, 2014
1 parent 0dbd3cb commit 9b5dd6b
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions urbansim/models/tests/test_hedonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest
from pandas.util import testing as pdt

from statsmodels.regression.linear_model import RegressionResultsWrapper

from .. import hedonic


Expand Down Expand Up @@ -47,5 +49,29 @@ def test_apply_filter_query_no_filter(test_df):
pdt.assert_frame_equal(filtered, expected)


# def test_fit_model(test_df):
# filters = []
def test_fit_model(test_df):
filters = []
model_exp = 'col1 ~ col2'
fit = hedonic.fit_model(test_df, filters, model_exp)
assert isinstance(fit, RegressionResultsWrapper)


def test_predict(test_df):
filters = ['col1 in [0, 2, 4]']
model_exp = 'col1 ~ col2'
fit = hedonic.fit_model(test_df, filters, model_exp)
predicted = hedonic.predict(
test_df.query('col1 in [1, 3]'), None, fit)
expected = pd.Series([1., 3.], index=['b', 'd'])
pdt.assert_series_equal(predicted, expected)


def test_predict_ytransform(test_df):
yt = lambda x: x / 2.
filters = ['col1 in [0, 2, 4]']
model_exp = 'col1 ~ col2'
fit = hedonic.fit_model(test_df, filters, model_exp)
predicted = hedonic.predict(
test_df.query('col1 in [1, 3]'), None, fit, ytransform=yt)
expected = pd.Series([0.5, 1.5], index=['b', 'd'])
pdt.assert_series_equal(predicted, expected)

0 comments on commit 9b5dd6b

Please sign in to comment.