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 inblueimport 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
sklearn==0.0
numpy
pandas