def transformation()

in 3_Models/model/predictor.py [0:0]


def transformation():
    """
    Do an inference on a single batch of data. In this sample server, we take
    data as CSV, convert it to a pandas data frame for internal use and then
    convert the predictions back to CSV (which really just means one prediction
    per line, since there's a single column.
    """
    data = None

    # Convert from CSV to pandas
    if flask.request.content_type == 'text/csv':
        data = flask.request.data.decode('utf-8')
        f = StringIO(data)
        data = pd.read_csv(f)            
    else:
        return flask.Response(
            response='This predictor only supports CSV data',
            status=415,
            mimetype='text/plain')

    print('Invoked with {} records'.format(data.shape[0]))

    # Do the prediction
    print("data=%s" % data)
    predictions = ScoringService.predict(data)
    print("predictions=%s" % predictions)

    # Convert from numpy back to CSV
    
    result = pd.DataFrame(predictions).to_csv(header=False, index=False)
    print("result=%s" % result)
    #result = out.getvalue()

    return flask.Response(response=result, status=200, mimetype='text/csv')