Created
March 14, 2021 08:54
-
-
Save shubham0204/331159f55f28cf65cfa6e7d156a3a2b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Predict a class for the given sample using the Random Forest. | |
fun predict( x : HashMap<String,String> ) : String { | |
// Create an empty array to store class labels. | |
val treeOutputs = Array( NUM_TREES ) { "" } | |
for ( i in 0 until NUM_TREES ) { | |
// Store the output of each DecisionTree in our forest. | |
treeOutputs[ i ] = forest[i].predict( x ) | |
println( "Prediction ${i+1} DecisionTree is ${treeOutputs[i]}") | |
} | |
// Get the majority label, which is our final prediction for the given sample. | |
val mostVotedLabel = treeOutputs.groupingBy{ it }.eachCount().maxBy{ entry -> entry.value }!!.key | |
println( "Most voted label : $mostVotedLabel" ) | |
return mostVotedLabel | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment