Apache Spark 2.x Machine Learning Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

  1. The signature for this method constructor is:
SparseVector(int size, int[] indices, double[] values)

The method inherits from the following which makes its concrete methods available to all routines:

interface class java.lang.Object  

There are several method calls related to vectors that are of interest:

    1.  Make a deep copy of the vector:
SparseVector Copy() 
    1. Convert to the SparseVector. You will do this if your vector is long and the density decreases after a number of operations (for example, zero out non-contributing members):
DenseVector toDense()
    1. Find the number of non-zero elements. This is useful so you can convert on-the-fly to the SparseVector if the density ID is low.
Int numNonzeros()
    1. Convert the vector to an array. This is often necessary when dealing with distributed operations that require 1:1 interactions with RDDs or proprietary algorithms that use Spark ML as a subsystem:
Double[] toArray()