Skip to content

← machine_learning package

SpikeSlabVBClassification

Classify data instances using binary sparse Bayesian logistic regression with a point-mass spike-and-slab variational posterior.

The current default mode aims to track the semantics of the sparsevb package as closely as practical, including fixed slab scale, fixed Beta-hyperprior parameters implied by the expected support size, package-style warm starts, and prediction from the raw posterior mean mu * gamma. One accepted difference remains in the default warm start: sparsevb uses glmnet::cv.glmnet(...) for ridge/lasso initialization, while the Python node uses an sklearn surrogate that solves the same kind of penalized logistic warm-start problem but is not numerically package-equivalent. Compared with relaxed spike-and-slab variational methods, this node keeps explicit per-feature inclusion probabilities. Optional empirical-Bayes updates remain available as non-reference behavior, but are disabled by default. As with other NeuroPype machine-learning nodes, a full labeled calibration packet is required before the fitted model can be used for prediction on subsequent data. More Info... Version 0.7.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

cond_field

The name of the instance data field that contains the conditions to be discriminated. This parameter is ignored if the packet has previously been processed by a DescribeStatisticalDesign node.

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

feature_scaling

Feature scaling to use. The spike-and-slab prior is scale-sensitive, so scaling the features is recommended for proper shrinkage behavior. The default of 'std' (standardization to zero mean and unit variance) is a good choice for most data. The 'robust' option uses median and interquartile range, which is more resilient to outliers.

  • verbose name: Feature Scaling
  • default value: std
  • port type: EnumPort
  • value type: str (can be None)

sample_size_factor

Sample size correction factor or effective sample size. When observations are not independent (e.g., multiple trials per participant), the effective information content may be considerably lower than the nominal sample count, causing the posterior to be overconfident. This parameter tempers the data-dependent terms of the variational bound by the factor n_eff/n, reducing the data's influence on the posterior to match the effective information content. Values between 0 and 1 (inclusive) are interpreted as a multiplicative factor applied to the actual number of observations; for instance, if you have 2000 trials from 30 participants, set this to 30/2000 = 0.015. Values > 1 must be integers and are interpreted as an absolute effective sample size; for instance, 30 means that the effective sample size is 30 regardless of the actual number of observations.

  • verbose name: Sample Size Correction
  • default value: 1.0
  • port type: FloatPort
  • value type: float (can be None)

expected_relevant_features

Expected number or fraction of relevant features. Controls the prior inclusion probability pi = p0/p, where p0 is the expected relevant count. Values between 0 and 1 are interpreted as a fraction of the total feature count; values greater than or equal to 1 must be integers and are interpreted as an absolute count. The default of 0.1 works well for moderate-dimensional problems (p up to ~2000). For very high-dimensional datasets (p > 5000), values of 0.02-0.05 are recommended to prevent over-selection of noise features.

  • verbose name: Expected Relevant Features
  • default value: 0.1
  • port type: FloatPort
  • value type: float (can be None)

slab_scale

Scale of the slab (relevant-feature) component. Controls the prior width of the non-zero coefficients on standardized features: larger values allow relevant features to take on larger coefficient values, while smaller values constrain them to stay closer to zero. The default of 1.0 works robustly across a wide range of problems; empirically, values from 0.5 to 2.0 produce nearly identical results on most datasets.

  • verbose name: Slab Scale
  • default value: 1.0
  • port type: FloatPort
  • value type: float (can be None)

include_bias

Include a bias (intercept) term. If disabled, input features should be centered or augmented with a constant feature.

  • verbose name: Include Bias Term
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

learn_inclusion_probability

Learn the global prior inclusion probability from the data during fitting. When enabled, the method adapts how many features it expects to be relevant based on what the data supports. When disabled (the default), the inclusion probability is fixed at the value implied by the expected relevant features parameter.

  • verbose name: Learn Inclusion Probability
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

learn_slab_scale

Learn the slab scale from the data during fitting. When enabled, the method adapts the expected magnitude of relevant coefficients based on the data. When disabled (the default), the slab scale is fixed at its configured value throughout fitting.

  • verbose name: Learn Slab Scale
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

support_threshold

Threshold on the estimated probability that a feature is relevant. Features whose inclusion probability meets or exceeds this threshold are reported as active in the support mask. The default of 0.5 selects features that are more likely relevant than not (the median probability model).

  • verbose name: Support Threshold
  • default value: 0.5
  • port type: FloatPort
  • value type: float (can be None)

max_iterations

Maximum number of coordinate-ascent (CAVI) sweeps. Convergence typically occurs within 100-200 iterations for most problems; the default of 500 is a generous safety margin.

  • verbose name: Maximum Iterations
  • default value: 500
  • port type: IntPort
  • value type: int (can be None)

convergence_tolerance

Convergence tolerance on the maximum change in posterior inclusion probabilities or posterior mean coefficients over a full sweep. The default of 1e-5 yields tight convergence; values up to 1e-4 are acceptable for faster fitting with minimal accuracy loss.

  • verbose name: Convergence Tolerance
  • default value: 1e-05
  • port type: FloatPort
  • value type: float (can be None)

laplace_solver

Solver for the inner CAVI coordinate sweep. 'scipy' uses scipy.optimize.minimize with L-BFGS-B for the 2D Laplace subproblem (the reference implementation). 'newton' replaces that with a hand-rolled 2D damped Newton iteration using the closed-form Hessian, which is numerically equivalent but avoids scipy's per-call overhead. 'numba' additionally JIT-compiles the entire per-feature sweep (x_appm updates, coef_lin dot product, Newton iteration, alpha update) as a single fused kernel, which is the fastest strictly-IEEE option for moderate to large feature counts. 'numba_fastmath' is the same kernel built with LLVM fast-math (reassoc, reciprocal, finite-only); it is typically 20-50% faster again but permits small reorderings at the ~1e-14 level. All numba variants pay a one-time JIT compilation cost on first use in a process (cached to disk).

  • verbose name: Laplace Subproblem Solver
  • default value: numba_fastmath
  • port type: EnumPort
  • value type: str (can be None)

random_seed

Random seed. Different values may give slightly different outcomes.

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

initialize_once

Calibrate the model only once. If set to False, then this node recalibrates whenever a non-streaming data chunk is received that has both training labels and associated training instances.

  • verbose name: Calibrate Only Once
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

dont_reset_model

Do not reset the model when the preceding graph is changed.

  • verbose name: Do Not Reset Model
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

probabilistic

Use probabilistic outputs. If enabled, the node will output for each class the predicted probability that a given trial belongs to that class.

  • verbose name: Output Probabilities
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

verbosity

Verbosity level. Higher values print more fitting diagnostics.

  • verbose name: Verbosity Level
  • default value: 0
  • port type: IntPort
  • value type: int (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)