Created
August 13, 2020 08:58
-
-
Save mostafam/4a0df7c81e0d08b4c4f6a8bba2d39e00 to your computer and use it in GitHub Desktop.
Read MLeap and score the LeapFrame
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
scala> import ml.combust.bundle.BundleFile | |
scala> import ml.combust.mleap.runtime.MleapSupport._ | |
scala> import resource._ | |
scala> import ml.combust.mleap.core.types._ | |
scala> import ml.combust.mleap.runtime.frame.{DefaultLeapFrame, Row} | |
// creating LeapFrame equivalent to the DataFrame above | |
scala> val schema = StructType(StructField("email", ScalarType.String), | |
| StructField("first_name", ScalarType.String)).get | |
scala> val data = Seq(Row("john.doe@gmail.com", "John"), Row("JackieChan234@xyz.com","jack"), Row("ping_pong@missed.org","Al")) | |
scala> val leapFrame = DefaultLeapFrame(schema, data) | |
// importing the MLeap bundle | |
scala> val bundle = (for(bundleFile <- managed(BundleFile("jar:file:MLeap.zip"))) yield { | |
| bundleFile.loadMleapBundle().get | |
| }).opt.get | |
scala> val mleapPipeline = bundle.root | |
// scoring the LeapFrame | |
scala> val outputLeapFrame = mleapPipeline.transform(leapFrame).get | |
scala> outputLeapFrame.dataset | |
res1: Seq[ml.combust.mleap.runtime.frame.Row] = List(Row(john.doe@gmail.com,John,0.0,1.0,DenseTensor([D@ca72afb,List(2))), Row(JackieChan234@xyz.com,jack,1.0,1.0,DenseTensor([D@3e4dabcb,List(2))), Row(ping_pong@missed.org,Al,2.0,0.0,DenseTensor([D@2b24fcba,List(2)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment