neupy.algorithms.competitive.lvq module

class neupy.algorithms.competitive.lvq.LVQ[source]

Learning Vector Quantization (LVQ) algorithm.

Parameters: 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: sum(prototypes_per_class) == n_subclasses len(prototypes_per_class) == n_classes The None value will distribute approximately equal number of subclasses per each class. It’s approximately, because in casses when n_subclasses % n_classes != 0 there is no way to distribute equal number of subclasses per each class. Defaults to None. step : float Learning rate, defaults to 0.1. n_updates_to_stepdrop : int or None If this options is not equal to None then after every update LVQ reduces step size and do it until number of applied updates would reach the n_updates_to_stepdrop value. The minimum possible step size defined in the minstep parameter. Be aware that number of updates is not the same as number of epochs. LVQ applies update after each propagated sample through the network. Relations between this parameter and maximum number of epochs is following n_updates_to_stepdrop = n_samples * n_max_epochs  If parameter equal to None then step size wouldn’t be reduced after each update. Defaults to None. minstep : float Step size would never be lower than this value. This property useful only in case if n_updates_to_stepdrop is not None. Defaults to 1e-5. show_epoch : int or str This property controls how often the network will display information about training. There are two main syntaxes for this property. You can define it as a positive integer number. It defines how offen would you like to see summary output in terminal. For instance, number 100 mean that network shows summary at 100th, 200th, 300th ... epochs. String defines number of times you want to see output in terminal. For instance, value '2 times' mean that the network will show output twice with approximately equal period of epochs and one additional output would be after the finall epoch. Defaults to 1. shuffle_data : bool If it’s True class shuffles all your training data before training your network, defaults to True. epoch_end_signal : function Calls this function when train epoch finishes. train_end_signal : function Calls this function when train process finishes. verbose : bool Property controls verbose output interminal. True enables informative output in the terminal and False - disable it. Defaults to False.

Notes

• Input data needs to be normalized, because LVQ uses Euclidian distance to find clusters.
• Training error is just a ratio of miscassified samples

Methods

 predict(input_data) Predicts output for the specified input. fit(*args, **kwargs) Alias to the train method.
minstep = None[source]
n_classes = None[source]
n_inputs = None[source]
n_subclasses = None[source]
options = {'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'step': Option(class_name='BaseNetwork', value=NumberProperty(name="step")), 'show_epoch': Option(class_name='BaseNetwork', value=ShowEpochProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'epoch_end_signal': Option(class_name='BaseNetwork', value=Property(name="epoch_end_signal")), 'train_end_signal': Option(class_name='BaseNetwork', value=Property(name="train_end_signal")), 'n_inputs': Option(class_name='LVQ', value=IntProperty(name="n_inputs")), 'n_subclasses': Option(class_name='LVQ', value=IntProperty(name="n_subclasses")), 'n_classes': Option(class_name='LVQ', value=IntProperty(name="n_classes")), 'prototypes_per_class': Option(class_name='LVQ', value=TypedListProperty(name="prototypes_per_class")), 'weight': Option(class_name='LVQ', value=Property(name="weight")), 'n_updates_to_stepdrop': Option(class_name='LVQ', value=IntProperty(name="n_updates_to_stepdrop")), 'minstep': Option(class_name='LVQ', value=NumberProperty(name="minstep"))}[source]
predict(input_data)[source]

Return prediction results for the input data.

Parameters: input_data : array-like array-like
prototypes_per_class = None[source]
train(input_train, target_train, *args, **kwargs)[source]

Method train neural network.

Parameters: input_train : array-like target_train : array-like or None input_test : array-like or None target_test : array-like or None epochs : int Defaults to 100. epsilon : float or None Defaults to None.
train_epoch(input_train, target_train)[source]
training_step[source]
weight = None[source]
class neupy.algorithms.competitive.lvq.LVQ2[source]

Learning Vector Quantization 2 (LVQ2) algorithm. Improved version for the LVQ algorithm.

Parameters: epsilon : float Ration between to closest subclasses that triggers double weight update. Defaults to 0.1. 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: sum(prototypes_per_class) == n_subclasses len(prototypes_per_class) == n_classes The None value will distribute approximately equal number of subclasses per each class. It’s approximately, because in casses when n_subclasses % n_classes != 0 there is no way to distribute equal number of subclasses per each class. Defaults to None. step : float Learning rate, defaults to 0.1. n_updates_to_stepdrop : int or None If this options is not equal to None then after every update LVQ reduces step size and do it until number of applied updates would reach the n_updates_to_stepdrop value. The minimum possible step size defined in the minstep parameter. Be aware that number of updates is not the same as number of epochs. LVQ applies update after each propagated sample through the network. Relations between this parameter and maximum number of epochs is following n_updates_to_stepdrop = n_samples * n_max_epochs  If parameter equal to None then step size wouldn’t be reduced after each update. Defaults to None. minstep : float Step size would never be lower than this value. This property useful only in case if n_updates_to_stepdrop is not None. Defaults to 1e-5. show_epoch : int or str This property controls how often the network will display information about training. There are two main syntaxes for this property. You can define it as a positive integer number. It defines how offen would you like to see summary output in terminal. For instance, number 100 mean that network shows summary at 100th, 200th, 300th ... epochs. String defines number of times you want to see output in terminal. For instance, value '2 times' mean that the network will show output twice with approximately equal period of epochs and one additional output would be after the finall epoch. Defaults to 1. shuffle_data : bool If it’s True class shuffles all your training data before training your network, defaults to True. epoch_end_signal : function Calls this function when train epoch finishes. train_end_signal : function Calls this function when train process finishes. verbose : bool Property controls verbose output interminal. True enables informative output in the terminal and False - disable it. Defaults to False.

Notes

• Input data needs to be normalized, because LVQ uses Euclidian distance to find clusters.
• Training error is just a ratio of miscassified samples
epsilon = None[source]
options = {'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'step': Option(class_name='BaseNetwork', value=NumberProperty(name="step")), 'show_epoch': Option(class_name='BaseNetwork', value=ShowEpochProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'epoch_end_signal': Option(class_name='BaseNetwork', value=Property(name="epoch_end_signal")), 'train_end_signal': Option(class_name='BaseNetwork', value=Property(name="train_end_signal")), 'n_inputs': Option(class_name='LVQ', value=IntProperty(name="n_inputs")), 'n_subclasses': Option(class_name='LVQ', value=IntProperty(name="n_subclasses")), 'n_classes': Option(class_name='LVQ', value=IntProperty(name="n_classes")), 'prototypes_per_class': Option(class_name='LVQ', value=TypedListProperty(name="prototypes_per_class")), 'weight': Option(class_name='LVQ', value=Property(name="weight")), 'n_updates_to_stepdrop': Option(class_name='LVQ', value=IntProperty(name="n_updates_to_stepdrop")), 'minstep': Option(class_name='LVQ', value=NumberProperty(name="minstep")), 'epsilon': Option(class_name='LVQ2', value=NumberProperty(name="epsilon"))}[source]
train_epoch(input_train, target_train)[source]
class neupy.algorithms.competitive.lvq.LVQ21[source]

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

Parameters: epsilon : float Ration between to closest subclasses that triggers double weight update. Defaults to 0.1. 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: sum(prototypes_per_class) == n_subclasses len(prototypes_per_class) == n_classes The None value will distribute approximately equal number of subclasses per each class. It’s approximately, because in casses when n_subclasses % n_classes != 0 there is no way to distribute equal number of subclasses per each class. Defaults to None. step : float Learning rate, defaults to 0.1. n_updates_to_stepdrop : int or None If this options is not equal to None then after every update LVQ reduces step size and do it until number of applied updates would reach the n_updates_to_stepdrop value. The minimum possible step size defined in the minstep parameter. Be aware that number of updates is not the same as number of epochs. LVQ applies update after each propagated sample through the network. Relations between this parameter and maximum number of epochs is following n_updates_to_stepdrop = n_samples * n_max_epochs  If parameter equal to None then step size wouldn’t be reduced after each update. Defaults to None. minstep : float Step size would never be lower than this value. This property useful only in case if n_updates_to_stepdrop is not None. Defaults to 1e-5. show_epoch : int or str This property controls how often the network will display information about training. There are two main syntaxes for this property. You can define it as a positive integer number. It defines how offen would you like to see summary output in terminal. For instance, number 100 mean that network shows summary at 100th, 200th, 300th ... epochs. String defines number of times you want to see output in terminal. For instance, value '2 times' mean that the network will show output twice with approximately equal period of epochs and one additional output would be after the finall epoch. Defaults to 1. shuffle_data : bool If it’s True class shuffles all your training data before training your network, defaults to True. epoch_end_signal : function Calls this function when train epoch finishes. train_end_signal : function Calls this function when train process finishes. verbose : bool Property controls verbose output interminal. True enables informative output in the terminal and False - disable it. Defaults to False.

Notes

• Input data needs to be normalized, because LVQ uses Euclidian distance to find clusters.
• Training error is just a ratio of miscassified samples
options = {'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'step': Option(class_name='BaseNetwork', value=NumberProperty(name="step")), 'show_epoch': Option(class_name='BaseNetwork', value=ShowEpochProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'epoch_end_signal': Option(class_name='BaseNetwork', value=Property(name="epoch_end_signal")), 'train_end_signal': Option(class_name='BaseNetwork', value=Property(name="train_end_signal")), 'n_inputs': Option(class_name='LVQ', value=IntProperty(name="n_inputs")), 'n_subclasses': Option(class_name='LVQ', value=IntProperty(name="n_subclasses")), 'n_classes': Option(class_name='LVQ', value=IntProperty(name="n_classes")), 'prototypes_per_class': Option(class_name='LVQ', value=TypedListProperty(name="prototypes_per_class")), 'weight': Option(class_name='LVQ', value=Property(name="weight")), 'n_updates_to_stepdrop': Option(class_name='LVQ', value=IntProperty(name="n_updates_to_stepdrop")), 'minstep': Option(class_name='LVQ', value=NumberProperty(name="minstep")), 'epsilon': Option(class_name='LVQ2', value=NumberProperty(name="epsilon"))}[source]
train_epoch(input_train, target_train)[source]
class neupy.algorithms.competitive.lvq.LVQ3[source]

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

Parameters: 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: sum(prototypes_per_class) == n_subclasses len(prototypes_per_class) == n_classes The None value will distribute approximately equal number of subclasses per each class. It’s approximately, because in casses 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 or str This property controls how often the network will display information about training. There are two main syntaxes for this property. You can define it as a positive integer number. It defines how offen would you like to see summary output in terminal. For instance, number 100 mean that network shows summary at 100th, 200th, 300th ... epochs. String defines number of times you want to see output in terminal. For instance, value '2 times' mean that the network will show output twice with approximately equal period of epochs and one additional output would be after the finall epoch. Defaults to 1. shuffle_data : bool If it’s True class shuffles all your training data before training your network, defaults to True. epoch_end_signal : function Calls this function when train epoch finishes. train_end_signal : function Calls this function when train process finishes. verbose : bool Property controls verbose output interminal. True enables informative output in the terminal and False - disable it. Defaults to False.

Notes

• Input data needs to be normalized, because LVQ uses Euclidian distance to find clusters.
• Training error is just a ratio of miscassified samples
• Decreasing step and increasing number of training epochs can improve the performance.
options = {'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'step': Option(class_name='LVQ3', value=NumberProperty(name="step")), 'show_epoch': Option(class_name='BaseNetwork', value=ShowEpochProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'epoch_end_signal': Option(class_name='BaseNetwork', value=Property(name="epoch_end_signal")), 'train_end_signal': Option(class_name='BaseNetwork', value=Property(name="train_end_signal")), 'n_inputs': Option(class_name='LVQ', value=IntProperty(name="n_inputs")), 'n_subclasses': Option(class_name='LVQ', value=IntProperty(name="n_subclasses")), 'n_classes': Option(class_name='LVQ', value=IntProperty(name="n_classes")), 'prototypes_per_class': Option(class_name='LVQ', value=TypedListProperty(name="prototypes_per_class")), 'weight': Option(class_name='LVQ', value=Property(name="weight")), 'n_updates_to_stepdrop': Option(class_name='LVQ', value=IntProperty(name="n_updates_to_stepdrop")), 'minstep': Option(class_name='LVQ', value=NumberProperty(name="minstep")), 'epsilon': Option(class_name='LVQ2', value=NumberProperty(name="epsilon")), 'slowdown_rate': Option(class_name='LVQ3', value=NumberProperty(name="slowdown_rate"))}[source]
slowdown_rate = None[source]
step = None[source]
train_epoch(input_train, target_train)[source]