class neupy.algorithms.LVQ3[source]

Learning Vector Quantization 3 (LVQ3) algorithm. Improved version for the LVQ2.1 algorithm.

n_inputs : int

Number of input units. It should be equal to the number of features in the input data set.

n_subclasses : int, None

Defines total number of subclasses. Values should be greater or equal to the number of classes. None will set up number of subclasses equal to the number of classes. Defaults to None (or the same as n_classes).

n_classes : int

Number of classes in the data set.

prototypes_per_class : list, None

Defines number of prototypes per each class. For instance, if n_classes=3 and n_subclasses=8 then there are can be 3 subclasses for the first class, 3 for the second one and 2 for the third one (3 + 3 + 2 == 8). The following example can be specified as prototypes_per_class=[3, 3, 2].

There are two rules that apply to this parameter:

  1. sum(prototypes_per_class) == n_subclasses
  2. len(prototypes_per_class) == n_classes

The None value will distribute approximately equal number of subclasses per each class. It’s approximately, because, for cases, when n_subclasses % n_classes != 0 there is no way to distribute equal number of subclasses per each class.

Defaults to None.

epsilon : float

Ration between to closest subclasses that triggers double weight update. Defaults to 0.1.

slowdown_rate : float

Paremeter scales learning step in order to decrease it in case if the two closest subclasses predict target value correctly. Defaults to 0.4.

step : float

Learning rate, defaults to 0.01.

show_epoch : int

This property controls how often the network will display information about training. It has to be defined as positive integer. For instance, number 100 mean that network shows summary at 1st, 100th, 200th, 300th … and last epochs.

Defaults to 1.

shuffle_data : bool

If it’s True than training data will be shuffled before the training. Defaults to True.

signals : dict, list or function

Function that will be triggered after certain events during the training.

verbose : bool

Property controls verbose output in terminal. The True value enables informative output in the terminal and False - disable it. Defaults to False.


  • Input data needs to be normalized, because LVQ uses Euclidean distance to find clusters.
  • Training error is just a ratio of misclassified samples
  • Decreasing step and increasing number of training epochs can improve the performance.


>>> import numpy as np
>>> from neupy import algorithms
>>> X = np.array([[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [1, 2]])
>>> y = np.array([0, 0, 0, 1, 1, 1])
>>> lvqnet = algorithms.LVQ3(n_inputs=2, n_classes=2)
>>> lvqnet.train(X, y, epochs=100)
>>> lvqnet.predict([[2, 1], [-1, -1]])
array([1, 0])
one_training_update(X_train, y_train)[source]

Function would be trigger before run all training procedure related to the current epoch.

epoch : int

Current epoch number.

options = {'epsilon': Option(class_name='LVQ2', value=NumberProperty(name="epsilon")), 'minstep': Option(class_name='LVQ', value=NumberProperty(name="minstep")), 'n_classes': Option(class_name='LVQ', value=IntProperty(name="n_classes")), 'n_inputs': Option(class_name='LVQ', value=IntProperty(name="n_inputs")), 'n_subclasses': Option(class_name='LVQ', value=IntProperty(name="n_subclasses")), 'n_updates_to_stepdrop': Option(class_name='LVQ', value=IntProperty(name="n_updates_to_stepdrop")), 'prototypes_per_class': Option(class_name='LVQ', value=TypedListProperty(name="prototypes_per_class")), 'show_epoch': Option(class_name='BaseNetwork', value=IntProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'signals': Option(class_name='BaseNetwork', value=Property(name="signals")), 'slowdown_rate': Option(class_name='LVQ3', value=NumberProperty(name="slowdown_rate")), 'step': Option(class_name='LVQ3', value=NumberProperty(name="step")), 'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'weight': Option(class_name='LVQ', value=Property(name="weight"))}[source]
slowdown_rate = None[source]
step = None[source]