Ejemplo n.º 1
0
def test_daily(trace4, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    input_data = mdbf.create_input(
        trace4, mock_isd_weather_source)
    trace_data, temperature_data = input_data
    assert trace_data.shape == (100,)
    assert temperature_data.shape == (100,)
Ejemplo n.º 2
0
def test_basic_billing(input_billing_df, monkeypatch_temperature_data,
                       mock_isd_weather_source):
    m = CaltrackMonthlyModel(fit_cdd=True)
    assert str(m).startswith("Caltrack")
    assert m.n is None
    assert m.params is None
    assert m.r2 is None
    assert m.rmse is None
    assert m.y is None

    output = m.fit(input_billing_df)

    assert "r2" in output
    assert "rmse" in output
    assert "cvrmse" in output
    assert "model_params" in output
    assert "n" in output

    assert 'formula' in m.params
    assert 'X_design_info' in m.params
    assert 'coefficients' in m.params

    index = pd.date_range('2011-01-01', freq='D', periods=365, tz=pytz.UTC)
    formatter = ModelDataBillingFormatter()
    formatted_predict_data = formatter.create_demand_fixture(
        index, mock_isd_weather_source)

    outputs, variance = m.predict(formatted_predict_data, summed=False)
    assert outputs.shape == (365, )
    assert all(variance > 0)

    outputs, variance = m.predict(formatted_predict_data, summed=True)
    assert outputs > 0
    assert variance > 0
Ejemplo n.º 3
0
def test_empty(trace2, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    input_data = mdbf.create_input(trace2, mock_isd_weather_source)
    trace_data, temperature_data = input_data
    assert trace_data.shape == (0, )
    assert temperature_data.shape == (0, )

    description = mdbf.describe_input(input_data)
    assert description.get('start_date') is None
    assert description.get('end_date') is None
    assert description.get('n_rows') == 0
def test_empty(trace2, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    input_data = mdbf.create_input(
        trace2, mock_isd_weather_source)
    trace_data, temperature_data = input_data
    assert trace_data.shape == (0,)
    assert temperature_data.shape == (0,)

    description = mdbf.describe_input(input_data)
    assert description.get('start_date') is None
    assert description.get('end_date') is None
    assert description.get('n_rows') == 0
Ejemplo n.º 5
0
def test_basic_daily(trace1, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    input_data = mdbf.create_input(trace1, mock_isd_weather_source)

    trace_data, temperature_data = input_data
    assert trace_data.shape == (4, )
    assert temperature_data.shape == (2832, 1)

    description = mdbf.describe_input(input_data)
    assert description.get('start_date') == \
        datetime(2011, 1, 1, tzinfo=pytz.UTC)
    assert description.get('end_date') == \
        datetime(2011, 4, 29, tzinfo=pytz.UTC)
    assert description.get('n_rows') == 4
def test_basic_daily(trace1, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    input_data = mdbf.create_input(
        trace1, mock_isd_weather_source)

    trace_data, temperature_data = input_data
    assert trace_data.shape == (4,)
    assert temperature_data.shape == (2832, 1)

    description = mdbf.describe_input(input_data)
    assert description.get('start_date') == \
        datetime(2011, 1, 1, tzinfo=pytz.UTC)
    assert description.get('end_date') == \
        datetime(2011, 4, 29, tzinfo=pytz.UTC)
    assert description.get('n_rows') == 4
Ejemplo n.º 7
0
def test_basic_usage(trace, monkeypatch_temperature_data,
                     mock_isd_weather_source):
    formatter = ModelDataBillingFormatter()
    model = BillingElasticNetCVModel(65, 65)

    formatted_input_data = formatter.create_input(trace,
                                                  mock_isd_weather_source)

    outputs = model.fit(formatted_input_data)
    assert 'upper' in outputs
    assert 'lower' in outputs
    assert 'n' in outputs
    assert 'r2' in outputs
    assert 'rmse' in outputs
    assert 'cvrmse' in outputs
    assert 'model_params' in outputs

    index = pd.date_range('2011-01-01',
                          freq='H',
                          periods=365 * 24,
                          tz=pytz.UTC)
    formatted_predict_data = formatter.create_demand_fixture(
        index, mock_isd_weather_source)

    outputs, variance = model.predict(formatted_predict_data, summed=False)
    assert outputs.shape == (365, )
    assert variance > 0

    index = pd.date_range('2011-01-01', freq='D', periods=365, tz=pytz.UTC)
    formatted_predict_data = formatter.create_demand_fixture(
        index, mock_isd_weather_source)

    outputs, variance = model.predict(formatted_predict_data, summed=False)
    assert outputs.shape == (365, )
    assert variance > 0

    outputs, variance = model.predict(formatted_predict_data, summed=True)
    assert outputs > 0
    assert variance > 0

    assert "ModelDataBillingFormatter" in str(ModelDataBillingFormatter)
Ejemplo n.º 8
0
def split_modeled_energy_trace_monthly(monthly_trace, modeling_period_set,
                                       mock_isd_weather_source):

    # create SplitModeledEnergyTrace
    formatter = ModelDataBillingFormatter()
    model_mapping = {
        'modeling_period_1': BillingElasticNetCVModel(65, 65),
        'modeling_period_2': BillingElasticNetCVModel(65, 65),
    }
    smet = SplitModeledEnergyTrace(monthly_trace, formatter, model_mapping,
                                   modeling_period_set)

    smet.fit(mock_isd_weather_source)
    return smet
Ejemplo n.º 9
0
def test_basic_usage(trace, mock_isd_weather_source):
    formatter = ModelDataBillingFormatter()
    model = BillingElasticNetCVModel(65, 65)

    formatted_input_data = formatter.create_input(
        trace, mock_isd_weather_source)

    outputs = model.fit(formatted_input_data)
    assert 'upper' in outputs
    assert 'lower' in outputs
    assert 'n' in outputs
    assert 'r2' in outputs
    assert 'rmse' in outputs
    assert 'cvrmse' in outputs
    assert 'model_params' in outputs

    index = pd.date_range('2011-01-01', freq='H', periods=365*24, tz=pytz.UTC)
    formatted_predict_data = formatter.create_demand_fixture(
        index, mock_isd_weather_source)

    outputs = model.predict(formatted_predict_data)
    assert outputs.shape == (365,)

    assert "ModelDataBillingFormatter" in str(ModelDataBillingFormatter)
Ejemplo n.º 10
0
def test_empty(trace2, monkeypatch_temperature_data, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    input_data = mdbf.create_input(trace2, mock_isd_weather_source)
    trace_data, temperature_data = input_data
    assert trace_data.shape == (0, )
    assert temperature_data.shape == (0, )

    description = mdbf.describe_input(input_data)
    assert description.get('start_date') is None
    assert description.get('end_date') is None
    assert description.get('n_rows') == 0

    missing = mdbf.get_input_data_mask(input_data)
    assert missing.shape == (0, )

    daily = mdbf.daily_trace_data(trace2)
    assert daily.shape[0] == 1
    assert_allclose(daily.sum(), trace2.data.value.sum())
Ejemplo n.º 11
0
def test_basic_monthly(trace1, monkeypatch_temperature_data,
                       mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    input_data = mdbf.create_input(trace1, mock_isd_weather_source)

    trace_data, temperature_data = input_data
    assert trace_data.shape == (4, )
    assert temperature_data.shape == (2832, 1)

    description = mdbf.describe_input(input_data)
    assert description.get('start_date') == \
        datetime(2011, 1, 1, tzinfo=pytz.UTC)
    assert description.get('end_date') == \
        datetime(2011, 4, 29, tzinfo=pytz.UTC)
    assert description.get('n_rows') == 4

    missing = mdbf.get_input_data_mask(input_data)
    assert missing.shape == (118, )
    assert sum(missing) == 0

    daily = mdbf.daily_trace_data(trace1)
    assert daily.shape[0] == 119
    assert_allclose(daily.sum(), trace1.data.value.sum())
Ejemplo n.º 12
0
def test_small(trace3, monkeypatch_temperature_data, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    with pytest.raises(ValueError):
        mdbf.create_input(trace3, mock_isd_weather_source)
Ejemplo n.º 13
0
def input_billing_df(monkeypatch_temperature_data, billing_trace,
                     mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    return mdbf.create_input(billing_trace, mock_isd_weather_source)
def test_small(trace3, mock_isd_weather_source):
    mdbf = ModelDataBillingFormatter()
    with pytest.raises(ValueError):
        mdbf.create_input(trace3, mock_isd_weather_source)
def input_billing_df(mock_isd_weather_source, billing_trace):
    mdbf = ModelDataBillingFormatter()
    return mdbf.create_input(billing_trace, mock_isd_weather_source)