Prediction Operator is a tool to make, adjust, or generate a prediction.
Prediction Operator consists of:
### Create a Prediction Operator
We will use a classic example of predicting iris species from an iris dataset in this example.
First, let's create a project that will make a prediction of species and deploy its model.
To create a Prediction Operator in Abacus.AI, we need to use API.
Inside the project, you go to Deployments>Prediction Operator>Create Prediction Operator (blue button in the top right corner)
There we give it a name and press “Create New Prediction Operator”.
This should open an Abacus.AI notebook with the prepopulated ID of the prediction operator we are creating and the project we are using. This notebook is a base example of how to create and update a Prediction Operator.
def initialize(fg):
return fg.groupby('species').mean().to_dict('index')
project_id
again while it is present in notebook)def predict(data, query):
from abacusai import ApiClient, ApiException
client = ApiClient()
project_id = 'your_project_id'
#check if data have required columns
missing_columns = set(['petal_length', 'petal_width', 'sepal_length', 'sepal_width']) - set(query.keys())
if missing_columns:
return client.evaluate_prompt(f'Tell that AI misses {missing_columns} columns to make a decision', temperature=0.5).content
#get deployment token
dep_token = client.list_deployment_tokens(project_id)[0]
#make prediction with model
predictions = client.predict(dep_token, 'dfjsaddf', query)
#convert it to the most probable specimen based on prediction
speciment = max(predictions['species'], key=predictions['species'].get)
#return answer enhanced by AI for readability
return client.evaluate_prompt(f'Tell that for parameters {query} AI thinks it is likely {speciment}. Usually this specimen average measurments are {data[speciment]}', temperature=0.5).content
fg = client.describe_feature_group_by_table_name('iris')
data = initialize(fg.load_as_pandas())
print(predict(data,dat.iloc[115,:].to_dict()))
operator = client.update_prediction_operator_from_functions(
prediction_operator_id=prediction_operator_id,
initialize_function=initialize,
predict_function=predict,
# If multiple, the order needs to match the initialize function
feature_group_ids=[fg.id],
package_requirements=[],
# choose one of 16, 32, 64 and 128
memory=16
)
operator
deployment = client.deploy_prediction_operator(prediction_operator_id=prediction_operator_id)
When the prediction operator is deployed, it is possible to check it inside the platform and get suggestions on Python/curl code for further usage inside the target platform. For this go to Deployments>Prediction API, select your Prediction Operator deployment in top dropout. Then you can change between python and curl API. You may use default values to see our check for values working, or try actual values like
{"sepal_length":6.4,"sepal_width":3.2,"petal_length":5.3,"petal_width":2.3}