Skip to content

Instantly share code, notes, and snippets.

@yzhang1991
Created October 6, 2017 19:28
Show Gist options
  • Save yzhang1991/1db3d95a8607f015ad2e9bc8e855bded to your computer and use it in GitHub Desktop.
Save yzhang1991/1db3d95a8607f015ad2e9bc8e855bded to your computer and use it in GitHub Desktop.
The classify UDF example
public String classify(double sepal_length, Double sepal_width, double petal_length, Double petal_width) {
if (knnc == null) {
throw new RuntimeException("Please run the IrisKNNClassifier procedure first to train the model.");
}
// Assemble the attributes together.
DenseInstance dataRow = new DenseInstance(attributeCount);
dataRow.put(0, sepal_length);
dataRow.put(1, sepal_width);
dataRow.put(2, petal_length);
dataRow.put(3, petal_width);
Object predictedClassValue = knnc.classify(dataRow);
return (String) predictedClassValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment