Creating a vector quantizer
You can use neural networks for vector quantization as well. Vector quantization is the N-dimensional version of "rounding off". This is very commonly used across multiple areas in computer vision, natural language processing, and machine learning in general.
How to do it…
- Create a new Python file, and import the following packages:
import numpy as np import matplotlib.pyplot as plt import neurolab as nl
- Let's load the input data from the
data_vq.txt
file:# Define input data input_file = 'data_vq.txt' input_text = np.loadtxt(input_file) data = input_text[:, 0:2] labels = input_text[:, 2:]
- Define a learning vector quantization (LVQ) neural network with two layers. The array in the last parameter specifies the percentage weightage to each output (they should sum up to 1):
# Define a neural network with 2 layers: # 10 neurons in input layer and 4 neurons in output layer net = nl.net.newlvq(nl.tool.minmax(data), 10, [0.25, 0.25, 0.25, 0...