def test_make_single_prediction():

    test_data = load_dataset(file_name='test.csv')
    single_test_input = test_data[0:1]

    subject = make_prediction(input_data=single_test_input)

    assert subject is not None
    assert isinstance(subject.get('prediction')[0], float)
    assert math.ceil(subject.get('prediction')[0]) == 112476
def test_make_multiple_predictions():

    test_data = load_dataset(file_name='test.csv')
    original_data_length = len(test_data)
    multiple_test_input = test_data

    subject = make_prediction(input_data=multiple_test_input)

    assert subject is not None
    assert len(subject.get('prediction')) == 1451

    assert len(subject.get('prediction')) != original_data_length
Beispiel #3
0
def test_make_single_prediction():
    # given
    test_data = load_dataset(file_name='xtest.csv')
    single_test_json = test_data[0:1].to_json(orient='records')
    # reads the 1st line of 'test.csv'

    # when
    subject = make_prediction(input_data=single_test_json)
    # print(subject.get('predictions')[0])
    # the above print statement was used to get the correct predicted value for
    # line 22 ~ subject to change after editing

    # then
    assert subject is not None
    assert isinstance(subject.get('predictions')[0],
                      float)  # calling the 'predictions' keyword from the dict
    assert math.ceil(subject.get('predictions')[0]) == 16  # see line 17
Beispiel #4
0
def test_make_multiple_predictions():
    # given
    test_data = load_dataset(file_name='xtest.csv')
    original_data_length = len(test_data)
    multiple_test_json = test_data.to_json(orient='records')

    # when
    subject = make_prediction(input_data=multiple_test_json)
    # print(original_data_length) # only work when tests fail
    # print(subject.get('predictions')) --> verified the points for each individual player is outputted

    # then
    assert subject is not None
    assert len(subject.get('predictions')) == 1034  # white box testing

    # we dont expect any rows to be filtered out
    assert len(subject.get('predictions')) == original_data_length
Beispiel #5
0
def predict():
    if request.method == 'POST':
        # Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')

        # Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_json=json_data)

        # Model prediction
        result = make_prediction(input_data=json_data)
        _logger.debug(f'Outputs: {result}')

        # Convert numpy ndarray to list
        predictions = result.get('predictions').tolist()
        version = result.get('version')

        # return JSON response
        return jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        })