Final part of a series to introduce the Vital AI software used to make predictions.
Go to beginning: Using the Vital AI software to make predictions
Now that we have the predictive model produced in the previous step, we can use it to make new predictions.
In order to make a prediction, we need an instance of the data object with properties set which will be the input features to the model.
Here is a snippet of code to load the model, instantiate a data object with properties, make the prediction, and output the result.
static main(args) { String modelJarPath = "./model/twentynews-model.jar" PredictModel model = new PredictModel() model.loadJar(new File(modelJarPath)) TwentyNewsDocument mydoc = new TwentyNewsDocument() mydoc.URI = "http://example.org/twentynews/TwentyNewsDocument/123" mydoc.title = "Let's play softball in the park!" mydoc.body = "Softball game tonight. Bring your bats!" model.predict(mydoc) List<Category> categories = mydoc.getNewsCategories() for( int i = 0 ; i < categories.size(); i++ ) { println "${categories[i].name}" } }
Now we can use such code in our application to make ongoing predictions.
marc:twentynewsclassificationapp hadfield$ ./bin/twentynewsclassifier ./model/twentynews-model-container.jar using domain jar: /Users/hadfield/LocalStorage/vitalhome/domain-jar/twentynews-1.0.2.jar Model jar path: ./model/twentynews-model-container.jar Input: mydoc.URI = "http://example.org/twentynews/TwentyNewsDocument/123" mydoc.title = "Let's play softball in the park!" mydoc.body = "Softball game tonight. Bring your bats!" Output: rec.sport.baseball 0.2307 rec.sport.hockey 0.1717 talk.politics.guns 0.1717 sci.space 0.1717 misc.forsale 0.1224
The “baseball” category was the top choice, with a score of 0.2307.
Hope you enjoyed this introduction to the Vital AI software.
We will present similar series for Natural Language Processing, Graph Analytics, Logical Inference, and other topics. Please contact us for additional information and to start using the Vital AI software!
Vital AI:
info@vital.ai
http://vital.ai/#contact