cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results for 
Search instead for 
Did you mean: 

Query ML Endpoint with R and Curl

BogdanV
New Contributor III

I am trying to get a prediction by querying the ML Endpoint on Azure Databricks with R. 
I'm not sure what is the format of the expected data. Is there any other problem with this code?

R Code.png

Thanks!!!

 

1 ACCEPTED SOLUTION

Accepted Solutions

BogdanV
New Contributor III

Hi Kaniz, 

I was able to find the solution. You should post this in the examples when you click "Query Endpoint"
You only have code for Browser, Curl, Python, SQL. You should add a tab for R
Here is the solution:

library(httr)
url <- "https://adb-********.azuredatabricks.net/serving-endpoints/********/invocations"
db_token="dap*******"
headers <- add_headers('Authorization'==paste('Bearer', db_token, sep=' '),
"Content-Type" = "application/json")

data='{"dataframe_split": {"columns": ["***columnName1String***", "***ColumnName2Integer****"], "data": [["val11", val12], ["val21", val22], ["val31", val32]]}}'
response= POST(url,headers,body=data)
results <- content(response, "parsed")

View solution in original post

1 REPLY 1

BogdanV
New Contributor III

Hi Kaniz, 

I was able to find the solution. You should post this in the examples when you click "Query Endpoint"
You only have code for Browser, Curl, Python, SQL. You should add a tab for R
Here is the solution:

library(httr)
url <- "https://adb-********.azuredatabricks.net/serving-endpoints/********/invocations"
db_token="dap*******"
headers <- add_headers('Authorization'==paste('Bearer', db_token, sep=' '),
"Content-Type" = "application/json")

data='{"dataframe_split": {"columns": ["***columnName1String***", "***ColumnName2Integer****"], "data": [["val11", val12], ["val21", val22], ["val31", val32]]}}'
response= POST(url,headers,body=data)
results <- content(response, "parsed")

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group