def test_validate_inputs(sample_input_data):
    # When
    validated_inputs, errors = validate_inputs(input_data=sample_input_data)

    # Then
    # we expect that 2 rows are removed due to missing vars
    # 1459 is the total number of rows in the test data set (test.csv)
    # and 1457 number returned after 2 rows are filtered out.
    assert len(sample_input_data) == 1459
    assert len(validated_inputs) == 1457
def test_validate_inputs_identifies_errors(sample_input_data):
    # Given
    test_inputs = sample_input_data.copy()

    # introduce errors
    test_inputs.at[1, "BldgType"] = 50  # we expect a string

    # When
    validated_inputs, errors = validate_inputs(input_data=test_inputs)

    # Then
    assert errors
    assert errors[1] == {"BldgType": ["Not a valid string."]}
def test_validate_inputs(sample_input_data):
    """These are static hardcodes; what's going on there. """
    # When
    validated_inputs, errors = validate_inputs(input_data=sample_input_data)

    # Then
    assert not errors

    # we expect that 2 rows are removed due to missing vars
    # 1459 is the total number of rows in the test data set (test.csv)
    # and 1457 number returned after 2 rows are filtered out.
    assert len(sample_input_data) == 1459
    assert len(validated_inputs) == 1457
Example #4
0
def test_pipeline_predict_takes_validated_input(pipeline_inputs,
                                                sample_input_data):
    # Given
    X_train, X_test, y_train, y_test = pipeline_inputs
    pipeline.price_pipe.fit(X_train, y_train)

    # When
    validated_inputs, errors = validate_inputs(input_data=sample_input_data)
    predictions = pipeline.price_pipe.predict(
        validated_inputs[config.model_config.features])

    # Then
    assert predictions is not None
    assert errors is None
Example #5
0
def make_prediction(
    *,
    input_data: t.Union[pd.DataFrame, dict],
) -> dict:
    """Make a prediction using a saved model pipeline."""

    data = pd.DataFrame(input_data)
    validated_data, errors = validate_inputs(input_data=data)
    results = {"predictions": None, "version": _version, "errors": errors}

    if not errors:
        predictions = _price_pipe.predict(
            X=validated_data[config.model_config.features])
        _logger.info(f"Making predictions with model version: {_version} "
                     f"Predictions: {predictions}")
        results = {
            "predictions": predictions,
            "version": _version,
            "errors": errors
        }

    return results