Scala <console>:24: error: could not find implicit value for evidence parameter of type breeze.storage.DefaultArrayValue[Any]

StackOverflow https://stackoverflow.com/questions/23274856

  •  09-07-2023
  •  | 
  •  

Question

I'm working with Spark and Scala(new to both). I have this code:

val indices: List[Int] = List()
val featValues: List[Double] = List()
...
val vector = SparseVector(100000, indices.toArray, featValues.toArray)

But I keep getting this error:

<console>:24: error: could not find implicit value for evidence parameter of type breeze.storage.DefaultArrayValue[Any]
                      val vector = SparseVector(100000, indices.toArray, featValues.toArray)

I'm sure someone only familiar with Scala could help me. The documentation for SparseVector is:

http://people.apache.org/~pwendell/catalyst-docs/api/mllib/index.html#org.apache.spark.mllib.linalg.SparseVector

I searched Google and found this: Could not find implicit value for evidence parameter of type scala.reflect.ClassManifest[T]

But I have no idea how to interpret the answers.

EDIT: I was actually importing another SparseVector from breeze while I should be importing from org.apache.spark.mllib.linalg.SparseVector.

I started the interactive shell again and entered: import org.apache.spark.mllib.linalg.SparseVector

Now I'm getting error: not found: value SparseVector after repeating the same code above.

EDIT2: I should have been clear the "..." implied that I was initializing the lists.

Was it helpful?

Solution

It looks like you've not initialized indices and values, so scala at some point is trying to work with their default values. Also based on the documentation you've linked you need to create SparseVector with new (maybe there's no companion object?)

I can't test, but I suggest to try the following:

 val indices = Array(1,2,3) // indices is expected to be an array of Int
 val values = Array(1.0d,2.0d,3.0d) // values is an array of doubles       
 val v2 = new SparseVector(3, indices, values)

does this work? If it does, the problem may be in the part of code you omitted after val featValues

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top