Skip to content

← machine_learning package

BalanceClasses

Balance the per-class trial counts in the data.

A class here refers to a numerical group of trials/instances in some data (e.g., class 0 may be one set of experimental conditions, and class 1 may be another). The node ensures that the data contain equal proportions of trials across these classes, which is sometimes necessary to ensure that downstream statistics and/or machine learning are sound (e.g., not unfairly biased towards an over-represented class, or accurately quantifying things like the error rate of ML models when all classes are being equally likely to occur in the data). This node should be called after AssignTargets (or an equivalent node that associates instances with numeric classes), and can be used on either continuous or segmented data. Note that, if you use this node on continuous data, this node will drop all event markers that are not of one of the designated target classes (as set via e.g., AssignTargets). Typically that is all markers where the TargetValue is set to the special value nan. Version 1.2.0

Ports/Properties

data

Data to process.

  • verbose name: Data
  • default value: None
  • port type: DataPort
  • value type: Packet (can be None)
  • data direction: INOUT

strategy

Strategy to apply. Duplicate will only duplicate under-represented trials, and drop will only drop excess over-represented trials. Mixed sets the target number of trials to the mean of the class trial counts, and duplicates or drops trials for each class accordingly to reach it. With target, under-represented trials will be duplicated and over-represented trials will be dropped to meet the target trial count specified in the target_count property. Bypass causes the node to do nothing.

  • verbose name: Strategy
  • default value: duplicate
  • port type: EnumPort
  • value type: str (can be None)

max_factor

Maximum factor by which to duplicate trials if the duplicate strategy is selected, or by which to reduce trials if the drop strategy is selected, after which the other class(es) or dropped or duplicated, respectively, until the classes are balanced. Ignored if None or 0 or the mixed strategy is used.

  • verbose name: Max Factor
  • default value: None
  • port type: IntPort
  • value type: int (can be None)

target_count

Target number of trials per class. This only applies if the strategy is set to target. In this case, all classes will be duplicated or dropped as needed in order to reach the target count per class. Ignored if None or 0.

  • verbose name: Target Count
  • default value: None
  • port type: IntPort
  • value type: int (can be None)

field_name

Name of field containing the classes to rebalance. In the output, values of this field will occur approximately equally in the given instances. Only change this from TargetValue if the named field has been added to the Instance axis upstream.

  • verbose name: Field Name
  • default value: TargetValue
  • port type: StringPort
  • value type: str (can be None)

binning_field

Optional name of field to bin on. This will, for each unique value in this field, perform the balancing within all instances where the field takes on the same value.

  • verbose name: Binning Field
  • default value:
  • port type: StringPort
  • value type: str (can be None)

randseed

Optionally the random seed to use to get deterministic results.

  • verbose name: Randseed
  • default value: 12345
  • port type: IntPort
  • value type: int (can be None)

verbose

Print info and warning messages. 0: no output; 1: print results only; 2: print errors/warnings; 3: print all.

  • verbose name: Verbose
  • default value: 3
  • port type: EnumPort
  • value type: str (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

  • verbose name: Set Breakpoint (Debug Only)
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

  • verbose name: Metadata
  • default value: {}
  • port type: DictPort
  • value type: dict (can be None)