Skip to content

Instantly share code, notes, and snippets.

// You can run this gist in a scala console
import java.awt.image.{BufferedImage}
import java.awt.Color
// Set image pixel at (0, 0)
val image = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY)
val b: Byte = 26
val color = new Color(b & 0xff, b & 0xff, b & 0xff)
image.setRGB(0, 0, color.getRGB)
@smurching
smurching / keras_vector_transformer.py
Last active November 17, 2017 03:11
KerasVectorTransformer
# Import transformer
from sparkdl.transformers import KerasVectorTransformer
# Create input DataFrame
data = [(Vectors.sparse(5, [(1, 1.0), (3, 7.0)]),),
(Vectors.dense([2.0, 0.0, 3.0, 4.0, 5.0]),),
(Vectors.dense([4.0, 0.0, 0.0, 6.0, 7.0]),)]
df = spark.createDataFrame(data, ["features"])
# Create KerasVectorTransformer
import numpy as np
from matplotlib import pyplot as plt
def make_plot(X, y, clf, title, filename):
'''
Plots the decision boundary of the classifier <clf> (assumed to have been fitted
to X via clf.fit()) against the matrix of examples X with corresponding labels y.
Uses <title> as the title of the plot, saving the plot to <filename>.
'''