我发现关于MLeap的很多积极反馈——这是一个允许快速评分的库。它基于一个转换为MLeap包的模型运行。
但是在评分之前的数据准备阶段呢?
有没有什么有效的方法可以将’Spark ML数据准备流程’(在训练期间使用Spark框架运行)转换为高效、性能优化的字节码?
回答:
你可以使用MLeap轻松地序列化你的整个PipelineModel(包含特征工程和模型训练)。
注意:以下代码有点旧,现在你可能可以使用更清晰的API了。
// Mleap PipelineModel Serialization into a single .zip fileval sparkBundleContext = SparkBundleContext().withDataset(pipelineModel.transform(trainData))for(bundleFile <- managed(BundleFile(s"jar:file:${mleapSerializedPipelineModel}"))) { pipelineModel.writeBundle.save(bundleFile)(sparkBundleContext).get}// Mleap code: Deserialize model from local filesystem (without any Spark dependency)val mleapPipeline = (for(bf <- managed(BundleFile(s"jar:file:${modelPath}"))) yield { bf.loadMleapBundle().get.root}).tried.get
需要注意的是,如果你在Spark中定义了自己的Estimators/Transformers,它们也需要对应的MLeap版本。