Categories:

Social Share

Sample structured Data Prediction model deployment for reference

The following files can be used as a reference for structured data inference -Iris Inference - Cluzters Vault and Google Docs - Cluzter Model Guidelines


Guidelines

Inference.zip Folder structure:

requirements.txt

Trained Model file

inference.py

Other files and folders used


Inference.py file format:

Import Statements

Onetime executable operations

{Ex: Loading the Model, label encoding  etc.}

def predict(Input arguments as per the use-case)

{

Data Preprocessing

Inference

Return output based on the use-case

}

*Do not change the naming convention for the entities marked inblue

  • inference.py and requirements.txt are mandatory files
  • inference.py should contain a function predict which takes one argument - a pandas dataframe. The return value should be a list of strings. For example, if the dataframe consists of 100 rows, the return value should be a list of 100 predictions (strings)


Sample inference.py
import pickle import numpy as np import pandas as pd model = pickle.load(open('model.pkl', 'rb')) class_names = ['setosa', 'versicolor', 'virginica'] def predict(df): #argument df is a pandas dataframe df = df[["SepalLengthCm", "SepalWidthCm", "PetalLengthCm", "PetalWidthCm"]] numpy_array = df.to_numpy() # Predict predictions = model.predict(numpy_array) output = [class_names[class_predicted] for class_predicted in predictions] return output #return will be a list of strings  ​

Sample requirements.txt
sklearn==0.0 numpy pandas ​​