def create_model_error_data_test(load_data, model, test_data_start_date,
                                 test_data_end_date, highlight_variable,
                                 highlight_value):
    #generates model forecast dependent on the model type
    if (model['model_type'] == 'displacement'):
        predicted_load_data = displacement_model.predict(
            load_data, test_data_start_date, test_data_end_date, model)
        y_pred = predicted_load_data['Load']
    elif (model['model_type'] == 'regression'):
        y_pred = regression_model.predict(load_data, test_data_start_date,
                                          test_data_end_date, model)

    test_data = load_data[(load_data.Date >= test_data_start_date)
                          & (load_data.Date <= test_data_end_date)]
    y_true = test_data['Load']

    highlighted_load_data = pd.DataFrame(columns=['Date'])
    if (highlight_variable != 'None'
            and highlight_value != 'None'):  #there is highlighted data chosen
        highlighted_load_data['Date'], highlighted_load_data[
            'y_axis'] = zip(  #get highlighted data entries
                *test_data.apply(lambda row: get_highlighted_entries_dataframe(
                    row, highlight_variable, highlight_value, 'Load'),
                                 axis=1))
    model_error_df = pd.DataFrame()
    model_error_df = create_model_error_data_visualised(
        test_data['Date'], y_pred, y_true, highlighted_load_data['Date'].
        tolist())  #generate model error data traces
    return model_error_df
コード例 #2
0
def get_test_data_metrics(load_data, models, test_data_start_date, test_data_end_date):
    test_data_metrics = []

    if (test_data_start_date == None or test_data_end_date == None): #if there is no test data selected, return no metrics
        return test_data_metrics
    test_data = load_data[(load_data.Date >= test_data_start_date)
                          & (load_data.Date <= test_data_end_date)]
    y_true = test_data['Load']
    for model in models: #iterate through all load forecasting models
        model_type = model['model_type']
        #predict logic for each type of load forecasting model
        if (model_type == 'displacement'):
            predicted_load_data = displacement_model.predict(
                load_data, test_data_start_date, test_data_end_date, model)
            y_pred = predicted_load_data['Load']
        elif (model_type == 'regression'):
            y_pred = regression_model.predict(
                load_data, test_data_start_date, test_data_end_date, model)

        model_error_df = pd.DataFrame() #model structure containing the error data used to calculate error distribution metrics
        model_error_df = create_model_error_data(
            model_error_df, y_true, y_pred)
        test_data_metrics.append(model_metrics.calculate_metrics(
            y_true, y_pred, model_error_df['APE'], model_error_df['Percentage']))
    return test_data_metrics
コード例 #3
0
 def test_predict_load(self):
     model = dict(coefficients=[5.0],
                  intercept=20,
                  x_columns=['Temperature'],
                  corrected_column=None)
     start_date = '2018-01-01'
     end_date = '2018-01-02'
     expected_output = [25, 30, 35]
     output = predict(self.load_data, start_date, end_date, model)
     self.assertEqual(expected_output, output)
コード例 #4
0
 def test_predict_load_with_corrected_column(self):
     model = dict(coefficients=[5.0],
                  intercept=20,
                  x_columns=['Temperature'],
                  corrected_column='Load Last Week')
     start_date = '2018-01-01'
     end_date = '2018-01-02'
     expected_output = [197, 414, 631]
     output = predict(self.load_data, start_date, end_date, model)
     self.assertEqual(expected_output, output)
コード例 #5
0
 def test_predict_load_multiple_coefficients(self):
     model = dict(coefficients=[5.0, 1.0],
                  intercept=100,
                  x_columns=['Temperature', 'Load Last Week'],
                  corrected_column=None)
     start_date = '2018-01-02'
     end_date = '2018-01-03'
     expected_output = [781, 1008, 1235]
     output = predict(self.load_data, start_date, end_date, model)
     self.assertEqual(expected_output, output)
def get_regression_model_traces(load_data, visualised_load_data, traces, model, model_name, model_color, y_axis, start_date, end_date):
    try:
        predicted_load_data = regression_model.predict(
            load_data, start_date, end_date, model, y_axis)
    except Exception as predict_error:
        raise predict_error
    
    predicted_load_traces = generate_traces(
        visualised_load_data['Date'], predicted_load_data, model_name, color=model_color)
    traces.extend(predicted_load_traces)
    return traces