Created
October 6, 2017 19:28
-
-
Save yzhang1991/1db3d95a8607f015ad2e9bc8e855bded to your computer and use it in GitHub Desktop.
The classify UDF example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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