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

3 REPLIES 3

Kaniz_Fatma
Community Manager
Community Manager

Hi @BogdanV, Please paste the code stack here.

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")

Hi @BogdanV

Thank you so much for sharing your solution! We greatly appreciate your input. I'm glad to hear that you were able to find a solution that works for you.

If you have any more questions or need further assistance, please don't hesitate to reach out. We're here to help!

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