mleap icon indicating copy to clipboard operation
mleap copied to clipboard

ClassCastException on spark PipelineModel created from loadSparkBundle

Open kiranchitturi opened this issue 8 years ago • 3 comments

Hi,

Props to the creators and maintainers of the mleap library. I have used it for run time and it's serving speed is blazing fast. I ran in to one error while implementing mleap library for our usecase

We have a logistic regression model that was serialized as a mleap bundle and I created spark PipelineModel from the bundle file using .loadSparkBundle().get.root.

However, the transform on PipelineModel failed with error java.lang.ClassCastException: org.apache.spark.ml.attribute.UnresolvedAttribute$ cannot be cast to org.apache.spark.ml.attribute.NominalAttribute due to labels not set on IndexToString transformer

I was able to workaround the issue by creating the IndexToString transformer with labels. This looks like a bug, would you like me to create a PR? WDYT?

diff --git a/mleap-spark/src/main/scala/org/apache/spark/ml/bundle/ops/feature/ReverseStringIndexerOp.scala b/mleap-spark/src/main/scala/org/apache/spark/ml/bundle/ops/feature/ReverseStringIndexerOp.scala
index 1b012f2..bcc80d4 100644
--- a/mleap-spark/src/main/scala/org/apache/spark/ml/bundle/ops/feature/ReverseStringIndexerOp.scala
+++ b/mleap-spark/src/main/scala/org/apache/spark/ml/bundle/ops/feature/ReverseStringIndexerOp.scala
@@ -66,7 +66,7 @@ class ReverseStringIndexerOp extends SimpleSparkOp[IndexToString] {
   }

   override def sparkLoad(uid: String, shape: NodeShape, model: IndexToString): IndexToString = {
-    new IndexToString(uid = uid)
+    new IndexToString(uid = uid).setLabels(model.getLabels)
   }

   override def sparkInputs(obj: IndexToString): Seq[ParamSpec] = {
Kiran’s-MacBook-Pro:mleap kiranchitturi$

kiranchitturi avatar Sep 12 '18 03:09 kiranchitturi

Hi @kiranchitturi , I am facing similar issue. Were you able to find a fix for this ?

balauppalapati avatar Nov 27 '18 12:11 balauppalapati

Facing the same issue.

nammmm avatar Feb 19 '19 20:02 nammmm

Fixed has been applied on mleap master https://github.com/combust/mleap/blob/master/mleap-spark/src/main/scala/org/apache/spark/ml/bundle/ops/feature/ReverseStringIndexerOp.scala#L69, closing this. Please re-open if you still an issue.

ancasarb avatar May 07 '20 20:05 ancasarb