O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extracting feature vectors

The final step in the processing pipeline is to extract the actual feature vectors that will be the input to our dimensionality reduction model. As we mentioned earlier, the raw grayscale pixel data will be our features. We will form the vectors by flattening out the two-dimensional pixel matrix. The BufferedImage class provides a utility method to do just this, which we will use in our function as follows:

def getPixelsFromImage(image: BufferedImage): Array[Double] = {   val width = image.getWidth   val height = image.getHeight   val pixels = Array.ofDim[Double](width * height)   image.getData.getPixels(0, 0, width, height, pixels) }

We can then combine these three functions into one utility function, which takes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required