java.lang.NoSuchMethodException: <Class>.<init>(java.lang.String) when copying custom Transformer

Azzy

Currently playing with custom tranformers in my spark-shell using both spark 2.0.1 and 2.2.1.

While writing a custom ml transformer, in order to add it to a pipeline, I noticed that there is an issue with the override of the copy method.

The copy method is called by the fit method of the TrainValidationSplit in my case.

The error I get :

java.lang.NoSuchMethodException: Custom.<init>(java.lang.String)
  at java.lang.Class.getConstructor0(Class.java:3082)
  at java.lang.Class.getConstructor(Class.java:1825)
  at org.apache.spark.ml.param.Params$class.defaultCopy(params.scala:718)
  at org.apache.spark.ml.PipelineStage.defaultCopy(Pipeline.scala:42)
  at Custom.copy(<console>:16)
  ... 48 elided

I then tried to directly call the copy method but I still get the same error.

Here is myclass and the call I perform :

import org.apache.spark.ml.Transformer
import org.apache.spark.sql.{Dataset, DataFrame}
import org.apache.spark.sql.types.{StructField, StructType, DataTypes}
import org.apache.spark.ml.param.{Param, ParamMap}

// Simple DF
val doubles = Seq((0, 5d, 100d), (1, 4d,500d), (2, 9d,700d)).toDF("id", "rating","views")


class Custom(override val uid: String) extends org.apache.spark.ml.Transformer {
  def this() = this(org.apache.spark.ml.util.Identifiable.randomUID("custom"))

  def copy(extra: org.apache.spark.ml.param.ParamMap): Custom = {
    defaultCopy(extra)
  }

  override def transformSchema(schema: org.apache.spark.sql.types.StructType): org.apache.spark.sql.types.StructType = {
    schema.add(org.apache.spark.sql.types.StructField("trending", org.apache.spark.sql.types.IntegerType, false))
  }

   def transform(df: org.apache.spark.sql.Dataset[_]): org.apache.spark.sql.DataFrame = {

    df.withColumn("trending", (df.col("rating") > 4 && df.col("views") > 40))
  }
}


val mycustom = new Custom("Custom")
// This call throws the exception. 
mycustom.copy(new org.apache.spark.ml.param.ParamMap())

Does anyone know if this is a known issue ? I cant seem to find it anywhere.

Is there another way to implement the copy method in a custom transformer ?

Thanks

Marsellus Wallace

These are a couple of things that I would change about your custom Transformer (also to enable SerDe operations of your PipelineModel):

e.g.

class Custom(override val uid: String) extends Transformer
    with DefaultParamsWritable {
      ...
      ...

}
object Custom extends DefaultParamsReadable[Custom]

Do take a look at the UnaryTransformer if you have only 1 Input/Output columns.

Finally, what's the need to call mycustom.copy(new ParamMap()) exactly??

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

java.lang.NoSuchMethodException: AffirmativeBased.<init>()

From Dev

What causing this exception java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]

From Dev

Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]

From Dev

Java - java.lang.NoSuchMethodException

From Java

java.lang.NoSuchMethodException for onCreate

From Dev

ProGuard java.lang.NoSuchMethodException

From Dev

java.lang.NoSuchMethodException for onCreate

From Dev

Error: java.lang.NoSuchMethodException: java.lang.Long.<init>() in spring MVC

From Dev

Java reflection: constructor for primitive int causes: java.lang.NoSuchMethodException: int.<init>(int)

From Dev

Java reflection: constructor for primitive int causes: java.lang.NoSuchMethodException: int.<init>(int)

From Dev

android java.lang.AssertionError: java.lang.NoSuchMethodException - Proguard

From Dev

java.lang.RuntimeException: java.lang.NoSuchMethodException: Hadoop mapreduce

From Dev

java.lang.RuntimeException: java.lang.NoSuchMethodException: Hadoop mapreduce

From Dev

java.lang.NoSuchMethodException: setHomeActionContentDescription [int]?

From Dev

java.lang.NoSuchMethodException: Unknown property

From Dev

Kafka throws java.lang.NoSuchMethodException

From Dev

getDeclaredMethod leading to java.lang.NoSuchMethodException

From Dev

A java.lang.NoSuchMethodException error (layouts)

From Dev

A java.lang.NoSuchMethodException error (layouts)

From Dev

java.lang.NoSuchMethodException struts servlet

From Dev

Exception while starting up the server : java.lang.NoSuchMethodException: org.springframework.security.authentication.ProviderManager.<init>()

From Dev

serverError: class java.lang.ClassCastException java.lang.Integer cannot be cast to java.lang.String

From Dev

No such property: id for class: java.lang.String

From Dev

java.lang.String class' value variable

From Dev

Java - This usage of java/lang/ProcessBuilder.<init>([Ljava/lang/String;)V can be vulnerable to Command Injection (Sonar)

From Dev

java.lang.NullPointerException error when method is called from a custom class

From Dev

Why Scala needs duplicate constructor? (java.lang.NoSuchMethodException)

From Dev

No default constructor found; nested exception is java.lang.NoSuchMethodException

From Dev

Struts Hibernate Integration with Annotations (java.lang.NoSuchMethodException)

Related Related

  1. 1

    java.lang.NoSuchMethodException: AffirmativeBased.<init>()

  2. 2

    What causing this exception java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]

  3. 3

    Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]

  4. 4

    Java - java.lang.NoSuchMethodException

  5. 5

    java.lang.NoSuchMethodException for onCreate

  6. 6

    ProGuard java.lang.NoSuchMethodException

  7. 7

    java.lang.NoSuchMethodException for onCreate

  8. 8

    Error: java.lang.NoSuchMethodException: java.lang.Long.<init>() in spring MVC

  9. 9

    Java reflection: constructor for primitive int causes: java.lang.NoSuchMethodException: int.<init>(int)

  10. 10

    Java reflection: constructor for primitive int causes: java.lang.NoSuchMethodException: int.<init>(int)

  11. 11

    android java.lang.AssertionError: java.lang.NoSuchMethodException - Proguard

  12. 12

    java.lang.RuntimeException: java.lang.NoSuchMethodException: Hadoop mapreduce

  13. 13

    java.lang.RuntimeException: java.lang.NoSuchMethodException: Hadoop mapreduce

  14. 14

    java.lang.NoSuchMethodException: setHomeActionContentDescription [int]?

  15. 15

    java.lang.NoSuchMethodException: Unknown property

  16. 16

    Kafka throws java.lang.NoSuchMethodException

  17. 17

    getDeclaredMethod leading to java.lang.NoSuchMethodException

  18. 18

    A java.lang.NoSuchMethodException error (layouts)

  19. 19

    A java.lang.NoSuchMethodException error (layouts)

  20. 20

    java.lang.NoSuchMethodException struts servlet

  21. 21

    Exception while starting up the server : java.lang.NoSuchMethodException: org.springframework.security.authentication.ProviderManager.<init>()

  22. 22

    serverError: class java.lang.ClassCastException java.lang.Integer cannot be cast to java.lang.String

  23. 23

    No such property: id for class: java.lang.String

  24. 24

    java.lang.String class' value variable

  25. 25

    Java - This usage of java/lang/ProcessBuilder.<init>([Ljava/lang/String;)V can be vulnerable to Command Injection (Sonar)

  26. 26

    java.lang.NullPointerException error when method is called from a custom class

  27. 27

    Why Scala needs duplicate constructor? (java.lang.NoSuchMethodException)

  28. 28

    No default constructor found; nested exception is java.lang.NoSuchMethodException

  29. 29

    Struts Hibernate Integration with Annotations (java.lang.NoSuchMethodException)

HotTag

Archive