Predicting Property Prices Using Oracle ADW and AutoML: Part 3 — Invoking Our AutoML Model Using the CLI

Jared Bach
5 min readJul 6, 2022

This blog is part of a series. To learn more about this demo and to gain access to the other steps, refer to this blog. In this blog, we are going to invoke the model using a REST endpoint in our terminals.

Before we exit our OML notebook, we are going to execute on more block of code. We are going to invoke our model on 3 different records inside our OML notebook. We are doing this, so after we invoke the model using the CLI, we can check that the predictions are the same. Create a new box and name it Validating the CLI. Execute the following code.

%python
import pandas as pd
validation = {"YEAR":"2007","BLOCK":6178,"LAND_SQFT":4000,"GROSS_SQFT":2535,"SALE_PRICE":1200000,"NEIGHBORHOOD":"DYKER HEIGHTS"},{"YEAR":"2015","BLOCK":8757,"LAND_SQFT":2500,"GROSS_SQFT":1538,"SALE_PRICE":1200000,"NEIGHBORHOOD":"MANHATTAN BEACH"},{"YEAR":"2017","BLOCK":2653,"LAND_SQFT":1197,"GROSS_SQFT":2000,"SALE_PRICE":1200000,"NEIGHBORHOOD":"GREENPOINT"}
df = pd.DataFrame.from_dict(validation)
oml_df = oml.push(df, dbtypes = { 'BLOCK':'NUMBER',
'LAND_SQFT':'NUMBER',
'GROSS_SQFT':'NUMBER',
'SALE_PRICE':'NUMBER',
'YEAR':'VARCHAR2(26)',
'NEIGHBORHOOD':'VARCHAR2(4000)'
})
mod_predict = nn_mod.predict(oml_df ,supplemental_cols = oml_df[:, ['SALE_PRICE']]).pull()
y_true = mod_predict['SALE_PRICE']
y_pred = mod_predict['PREDICTION']
z.show(mod_predict)

The output should look like this.

Make a mental note of these numbers — we will come back to these. If you wish to access this notebook, you can download it here. Let’s exit the OML notebook and navigate to our OML models. We can do this by clicking on the hamburger menu in the upper left-hand corner of the screen. Then, click on Models.

If you can recall, before we built the model inside our notebook, we added model_name = 'nn_brooklyn_nb' to the nn_mod.fit() function. We needed to do this, so we could then see the model listed here. Select the NN_BROOKLYN_NB model and then click Deploy.

Leave the name as-is and for URI, enter nn_brooklyn. The version is 1.0. Click OK.

Once the model finishes delpying, you will be able to see it listed under deployments.

Now, this model is deployed as a REST endpoint. You can view it under the Deployments tab of the Models section of Oracle Machine Learning, but more importantly you can issue a call to generate predictions. Let’s do exactly that using cURL.

I can generate predictions by setting some environment variables in a local Bash shell and issuing a few commands as a basic example. For details, see the documentation.

First, let’s retrieve our OML server URL. First go to your Database Actions homepage and then click Oracle Machine Learning Restful Services at the bottom of the page.

Copy the first URL listed and make a note of it. Leave off the ending where it has /omlusers/.

Next, let’s set some environment variables in our terminal that detail your tenancy and Autonomous Data Warehouse deployment:

export username='<db_username>'export password='<db_password>'export omlserver=https://mvdvitnosgjllaz-jaredadw.adb.us-ashburn-1.oraclecloudapps.com

In this code block, I set a few values, such as the OML server from the previous step and the username and password for the database user. Make sure you are using your own personal OML server and not the one I am using above.

Next, we get an access token, which provides authentication when calling the REST endpoint. Using the previous environment variables, we can issue the following call.

curl -i -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"grant_type":"password", "username":"'${username}'", "password":"'${password}'"}' "${omlserver}/omlusers/api/oauth2/v1/token"

This command outputs a JSON object, with the value of the “accesstoken” key being a long string. Copy and paste the following command to make one last environment variable, including the apostrophes wrapping the token.

export token='<accesstoken>'

Now, we can issue some calls against the model’s endpoint. We can issue the following command to get some model metadata and the model’s input parameters.

curl -X GET "${omlserver}/omlmod/v1/deployment/nn_brooklyn" \--header "Authorization: Bearer $token" | jq

This command generates the following result.

The following command issues the call to the endpoint using one set of records.

curl -X POST "${omlserver}/omlmod/v1/deployment/nn_brooklyn/score" \--header "Authorization: Bearer ${token}" \--header 'Content-Type: application/json' \-d '{"inputRecords":[{"BLOCK":1830,"GROSS_SQFT":3760,"LAND_SQFT":2000,"NEIGHBORHOOD":"BEDFORD STUYVESANT","YEAR":"2005"}]}'| jq

This is the result.

The following command issues the call to the endpoint using 3 different records.

curl -X POST "${omlserver}/omlmod/v1/deployment/nn_brooklyn/score" \--header "Authorization: Bearer ${token}" \--header 'Content-Type: application/json' \-d '{"inputRecords":[{"YEAR":"2007","BLOCK":6178,"LAND_SQFT":4000,"GROSS_SQFT":2535,"SALE_PRICE":1200000,"NEIGHBORHOOD":"DYKER HEIGHTS"},{"YEAR":"2015","BLOCK":8757,"LAND_SQFT":2500,"GROSS_SQFT":1538,"SALE_PRICE":1200000,"NEIGHBORHOOD":"MANHATTAN BEACH"},{"YEAR":"2017","BLOCK":2653,"LAND_SQFT":1197,"GROSS_SQFT":2000,"SALE_PRICE":1200000,"NEIGHBORHOOD":"GREENPOINT"}]}'| jq

This is the result.

Note that the predictions in the CLI are the same as the predictions made inside the OML notebook.

That’s all folks. Thanks so much for following along and making it to the end. To see any of the previous steps in this demo, refer to this blog.

--

--

GenZ business techie 👨🏻‍💻📉 lover of dogs and hummus 🇮🇱