Machine learning with IBM Watson AutoAI: Connecting the model API to a web app

About this video

In this final part of a three-part video series on experimenting, automating, and deploying a machine learning model using IBM® Watson™ AutoAI, learn about connecting the model API to a web app.

Part 1 explained data exploration and data visualization. The next part, Part 2, described how to run Watson AutoAI. The demo video ties it all together.

Transcript of this video

In the last video, we created an AutoAI experiment, which ran eight different pipelines against a metric, which was the root mean squared error. We then ranked and found our top performing pipelines, and then we saved that as a model. In this video, we’re going to go ahead and deploy that model and then test it. We can test that all within the Watson Studio interface.

After we make sure it’s running correctly, we can go ahead and connect and use some of the API credentials like the API key, the deployment ID, and the model ID. We’ll use that within our Flask application, and then use that API connection to get the info from Watson Studio and our deployed machine learning model. We’ll click on add deployment here in the deployments tab, and we’ll say YouTube deploy. You’ll see it’s a web service, and it’s initializing.

We’ll click on this. It’s still taking a couple seconds, so I’ll come back in a minute or two. Okay, so we waited a couple of minutes, and now we can go ahead and test our model. Let’s just make sure that it’s performing properly. So, give it a smoker. It’s about right that it’s sixteen thousand. So that looks about right. Now that we’ve tested the model, let’s go ahead and implement it. We’ll show you how to link a web application, which you saw in the first video.

Now that we have this deployed, I’ll show you how easy it is to actually implement this with the Watson Machine Learning service. We’ll click on this implementation tab. But first, let’s go ahead and actually clone this repository. I’ll just copy this. I’ll start a new window in VScode. I’ll do make a directory youtube-autoai, and then I’ll do a git clone. So now in here, we have the web app portion, and all we need to do is we have to go ahead and grab our ml instance ID. This deployment ID can be found right here. So we will add this deployment ID here. Save that, and then what we need here is a couple of things.

We need a bearer token. But first, we’ll get the ml instance ID. So we’ll duplicate this tab, and then we’ll go back into IBM cloud. You’re going to go and find the service. Now we’re going to find the machine learning service associated with the AutoAI experiment, which is this one. Then, here we have the API key and the instance ID. So first, we’ll grab the instance ID, and next we just have to do this bearer access token. We have the script in here, so if you go down in the step seven, we have the step to generate the access token.

All we have is this curl request here, and we have commands for Windows™ users as well. In this API key, one two three four five seven and nine, we’re going to grab our API key. We grab our API key from the Watson Machine Learning instance that’s associated with the AutoAI experiment. We paste it in here, and we just hit enter. We’ll get this big string, and the token lasts for an hour, so we’re just going to copy and paste right above this where this quote ends to this whole chunk here.

We’ll paste it into here. Be careful where you paste it. You want to make sure it’s inside the quotes, and that should be good to go. If we go into here, go into the web app directory. Note, we’re running Python 302, so it is tested with that. We just have to run a few things to install the prerequisites. All we have to do is we have to run this pip3 install command. Now just do a Flask run, and now you should have your insurance estimator up and running. Let’s give it a quick try.

Nice job!

So you see it’s working, and if we click yes, you get a much larger charge. So what we learned in this video is we learned how to deploy our model within Watson Studio. We then tested it within Watson Studio. And then we took all these API credentials, and we showed how to implement this and connect our Flask application to this deploy machine learning model. Of course, this can be done with any other data set, but I just wanted to show you that within 20 minutes you can get a nice deployed model and an easy front-end user interface to talk to that model and get predictions. So hopefully, you found this helpful. If you did, give me a thumbs up, and I’ll be sure to make more AI and machine learning content.

Thanks so much.