Skip to content

Instantly share code, notes, and snippets.

@a-agmon
Last active February 26, 2023 12:08
Show Gist options
  • Save a-agmon/b0a247c56f25afcecf16f56e4bb12a68 to your computer and use it in GitHub Desktop.
Save a-agmon/b0a247c56f25afcecf16f56e4bb12a68 to your computer and use it in GitHub Desktop.
case class PredictionResult(key: String, ts:Timestamp,
label: Float, prediction: Float, ratio: Float)
def predict(appId:String, recordsIter:Iterator[FeaturesRecord]):
Seq[PredictionResult] = {
val predDF = for {
(trainSeq, actualValSeq) <- getForecastDataset(appId, recordsIter.toSeq)
booster <- trainXGBBooster(trainSeq)
forecastedVal <- predictXGBBooster(appId, booster, actualValSeq)
} yield forecastedVal
predDF match {
case Success(predictionResults) => predictionResults
case Failure(exc) => throw new RuntimeException(s"prediction failed due to $exc")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment