-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Created scala function that trains a forest
and passes back to python context (#237)
- Loading branch information
1 parent
4bfaac9
commit 0fc736f
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package au.csiro.variantspark.api | ||
|
||
import au.csiro.variantspark.algo.{ | ||
RandomForest, | ||
RandomForestModel, | ||
RandomForestParams | ||
} | ||
import au.csiro.variantspark.input.{FeatureSource, LabelSource} | ||
|
||
/** Passes a trained random forest model back to the python wrapper | ||
*/ | ||
object RFModelTrainer { | ||
def trainModel( | ||
featureSource: FeatureSource, | ||
labelSource: LabelSource, | ||
params: RandomForestParams, | ||
nTrees: Int, | ||
rfBatchSize: Int | ||
): RandomForestModel = { | ||
val labels = labelSource.getLabels(featureSource.sampleNames) | ||
lazy val inputData = featureSource.features.zipWithIndex.cache() | ||
val rf = new RandomForest(params) | ||
val rfTrained = rf.batchTrain(inputData, labels, nTrees, rfBatchSize) | ||
rfTrained | ||
} | ||
} |