Ejemplo n.º 1
0
    def setUp(self):
        self.flask_app = app.test_client()

        # Adding users to authenticate against
        self.username = "******"
        self.password = "******"
        app.config['USERS'][self.username] = self.password

        app.config['MODEL'] = ModelWrapper.load(GIT_COMMIT)

        # in case of using data versioning, don't forget to pull test data from remote data repo

        # read held back test data
        self.test_data = pd.read_csv("resources/test.csv")
        self.min_performance = 0.8

        self.predictor = app.config['MODEL']
Ejemplo n.º 2
0
from flask import jsonify, request

from services.infrastructure.environment import training_host_url, debug_mode
from services.infrastructure.flask import init_flask
from services.infrastructure.git_info import GIT_COMMIT

from services.infrastructure.logging import initialize_logging
from services.infrastructure.environment import prediction_auth

from model.model_wrapper import ModelWrapper

# initialize flask application
TRAINING_POD_URL = training_host_url()
app, _executor, auth = init_flask()
app.config['USERS'] = prediction_auth()
app.config["MODEL"] = ModelWrapper.load(GIT_COMMIT)


@app.route('/predict', methods=['POST'])
@auth.login_required
def predict():
    """Provides the endpoint for getting new predictions from the developed model using a POST
    request json.

    HTTP Request Parameters
    -----------------------
    data : json
        Json post containing at least the *ModelWrapper.source_features*. Otherwise a error will
        be thrown

    HTTP Response
Ejemplo n.º 3
0
    logging.getLogger(__name__).info("Persisting the model...")
    classification_model.save(model_name)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Training model and saving it")
    parser.add_argument("--input",
                        "-i",
                        type=str,
                        help="Input file for training",
                        default="resources/train.csv")
    parser.add_argument("--output",
                        "-o",
                        type=str,
                        help="output model name",
                        default="local")
    parsed_args = parser.parse_args()

    train(model_name=GIT_COMMIT, train_data=parsed_args.input)

    model = ModelWrapper.load(GIT_COMMIT)

    # load test Dataframe
    test_df = pd.read_csv("resources/test.csv")
    print(test_df.to_dict(orient='list'))
    res = model.prep_and_predict(test_df.to_dict(orient='list'))
    print(res, test_df['Species'].values)

    print(accuracy_score(res['prediction'], test_df["Species"].values))