Python models

To create a python model, following steps are advised:

Define model input data

Variables consumed by model must be defined in csv format

model.csv
true;x1;STRING;;	
true;x2;DOUBLE;;
true;x3;INTEGER;;
true;x4;MAP;;
false;x5;VECTOR;;
true;x6;BOOLEAN;;sample description

Each line contains information about one variable including

  • field required indicator

  • variable name

  • variable type

  • list of enum values

  • optional description

Alternatively, python script to create file can be used

# Create .csv file with SCE parameters.
vars_def = """
true;x1;STRING;;	
true;x2;DOUBLE;;
true;x3;INTEGER;;
true;x4;MAP;;
false;x5;VECTOR;;
true;x6;BOOLEAN;;sample description
"""

model_file = open('./model.csv', 'wt')
model_file.write(vars_def)
model_file.close()

Serialize model

Model object must be saved into pickle file. Minimally the output structure of the model must be defined. Common machine learning libraries for instance sklearn , xgboostare supproted as well.

Prepare scoring script

Usually some data processing is needed. Thus in python script such operations can be prepared. Scoring .py script is obligatory and model object must be always returned.

Upload model to Scoring One

Previously creaded 3 files: model.csv, model.plk, model.py must be packed together into one zip file to be able to send to Scoring One.

Then set up enviromental variables before sending request

Finally use requests library to POST the data

Last updated