0

I am using the Google Prediction v1.5 Java Client with the "PredictionSample.java" sample program. I want to know that is there any jave example for creating the "com.google.api.services.prediction.model.Update" object. I have trained a model with the "language_id.txt" file and want to update the trained model using new training instances.

It seems that I could use

prediction.trainedmodels().update(String id, Update content)

to create a "com.google.api.services.prediction.model.Update" object, but it is not clear how to use the "Update" object's "setCsvInstance" and "setOutput" methods to properly input a new training instance. Moreover, it's not clear how to differentiate "regression" numerical value from "classification" string value in "setOutput" method as this method seems only accept Java "String" value.

Could anyone suggest codes for this usage. Thanks for any suggestion.

user1129812
  • 2,859
  • 8
  • 32
  • 45

1 Answers1

0

I didn´t find any example too. But I implemented the following code in my application and it is working. Hope this helps.

final String label = "My Label"; 
final List<java.lang.Object> csvInstance = new ArrayList<Object>();
// add your model´s features related to your label
csvInstance.add( "feature1" ); 
csvInstance.add( "feature2" );
csvInstance.add( "feature3" ); 

final Update update = new Update();
update.setCsvInstance( csvInstance );
update.setOutput( label );

final Prediction prediction = new Prediction.Builder( httpTransport, jsonFactory, credential ).setApplicationName( applicationName ).build();
prediction.trainedmodels().update( projectNumber, modelId, update ).execute();