Compatible Model APIは、常に最新のAPIをサポートし、すべてのバージョンのDataRobotとの下位互換性があります。
Compatible Model APIを使用するコードの例を以下に示します。
import com.datarobot.prediction.compatible.IPredictorInfo;
import com.datarobot.prediction.compatible.IRegressionPredictor;
import com.datarobot.prediction.compatible.Predictors;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
// data is being passed as a Java map
Map<String, Object> row = new HashMap<>();
row.put("a", 1);
row.put("b", "some string feature");
row.put("c", 999);
// below is an example of prediction of a single variable (regression)
// model id is the name of the .jar file
String regression_modelId = "5d2db3e5bad451002ac53318";
// get a regression predictor object given model
IRegressionPredictor regression_predictor =
Predictors.getPredictor(regression_modelId);
double scored_value = regression_predictor.score(row);
System.out.println("The predicted variable: " + scored_value);
// below is an example of prediction of class probabilities (classification)
// model id is the name of the .jar file
String classification_modelId = "5d36ee03962d7429f0a6be72";
// get a classification predictor object given model
IClassificationPredictor predictor =
Predictors.getPredictor(classification_modelId);
Map<String, Double> class_probabilities = predictor.score(row);
for (String class_label : class_probabilities.keySet()) {
System.out.println(String.format("The probability of the row belonging to class %s is %f",
class_label, class_probabilities.get(class_label)));
}
}
}