Skip to content

Classification Nodes

Summary

Reference: nodes that assign samples to classes — KNN, PLS-DA, SIMCA, and their evaluation.

Classification nodes assign spectra or feature rows to classes.

Nodes

  • classification.knn: You need a distance-based classifier after appropriate scaling or dimensionality reduction. Validation is owned by an explicit split plan outside this fit-only node.
  • classification.apply_knn: Apply the exact KNN reference set, scaling, distance, and voting state to new rows. Accepts only the KNN serializer.
  • classification.plsda: You want a latent-variable classifier for exactly-one-class spectral discrimination. Validation is owned by an explicit split plan outside this fit-only node. Uses the native Sherpa SIMPLS authority.
  • diagnostics.plsda_permutation: Check whether a PLS-DA development result exceeds a random-label null under an exchangeable design.
  • classification.apply_plsda: Apply fitted PLS2 coefficients and the declared maximum-response decision rule to new rows. Scores are responses, not probabilities; accepts only the PLS-DA serializer.
  • classification.simca: You want class-specific PCA models that can reject samples outside known classes. Validation is owned by an explicit split plan outside this fit-only node. Uses the native Sherpa SIMCA authority.
  • classification.apply_simca: Apply explicit class PCA models and their complete T²/Q limits to new rows. Can return unassigned; affinity is not probability; accepts only the SIMCA serializer.

Calibration and application safeguards

Numerical analysis refuses inputs containing excluded samples or variables. Materialize the active sample cohort with Filter Samples (source inclusion), and the active variables with an explicit variable-selection rule, before fitting. Excluded data cannot silently influence models or reference statistics.

KNN, PLS-DA, and SIMCA application require the fitted feature order, axis units, signal units, signal quantity, and measurement mode. Missing metadata must also match what was available at fit time. Convert incompatible signals explicitly before application. Refit older classifier states or saved artifacts that do not record this input identity.

PLS-DA application reports per-sample T² and Q, fitted screening limits, and an out-of-domain warning independently of the argmax class decision. A large class response is not a membership guarantee. Screening uses aggregate calibration statistics; it does not establish local support or analytical validation.

SIMCA uses the recorded positive eigenvalues, scaling factors, and acceptance limits exactly. Calibration, fitted application, and membership reporting share the same distance calculation, including for very small positive residual limits.

Key Outputs

Expect predictions, class probabilities, response scores, or affinities where appropriate, plus confusion matrices and split-aware metrics when validation is part of the workflow. Application is deliberately family-specific: no node may guess the model family, invent missing SIMCA limits, or reinterpret a numerical output as a probability.

KNN fits the exact configured neighbor count, distance rule, weighting rule, and optional autoscaling state. The node reports calibration-fit diagnostics, not validation performance. Use an explicit stratified or grouped split plan and the shared fold executor for validation; preprocessing and the classifier are then fit only on each training partition. The saved artifact carries the reference rows, encoded class identities, and fitted scaling vectors needed to reproduce scikit-learn's exact zero-distance and tie behavior. Scientific reference: Cover and Hart, Nearest Neighbor Pattern Classification, IEEE Transactions on Information Theory 13 (1967), 21–27, DOI 10.1109/TIT.1967.1053964.

PLS-DA fits PLS2 to a 0/1 dummy class table and assigns each sample to the largest predicted dummy response, following the usual rchemo::plsrda exactly-one-class rule. Its class_scores are regression responses, not posterior probabilities. The node performs one fit and carries no hidden cross-validation setting. The standard PLS-DA analysis template uses an explicit stratified train/test split; repeated or grouped validation uses the shared split-plan and fold-executor workflow. This applies to every dataset, not only grouped instrument studies. Report the class order, split record, confusion matrices, and fold-local metrics. Scientific reference: Barker and Rayens, Partial least squares for discrimination, Journal of Chemometrics 17 (2003), 166–173, DOI 10.1002/cem.785.

For a response-permutation check, connect the training partition to both the PLS-DA fit and the diagnostic node, including the same class labels and the fitted-state output. The diagnostic recomputes the state and refuses a different calibration population. It repeats the complete stratified or grouped fold-local fit and component search for the observed labels and for every seeded shuffle. Whole specimen groups remain intact; class labels move only among equal-sized groups in the same optional exchangeability block. Blocks come from a named column in the verified attached sample table; a free-standing vector is not accepted because its row identity is unknown. Insufficient class counts, invalid folds, population-fitted upstream preprocessing, and incomplete permutations stop the check without a p-value. For an input supplied as a bare array without provenance, the result records caller_declared_raw_array_no_recorded_preprocessing; it does not claim that unrecorded preparation was verified or refitted within folds. The finite-sample value is (1 + null scores at least as high as observed) / (1 + completed permutations). An identity draw remains in the null sample. This is development evidence against exchangeable random labels, not an independent test, an application-domain check, or proof of causation. CV-ANOVA is explicitly unavailable for this PLS-DA statistic.

SIMCA Note

SIMCA is not just nearest-class classification. It can reject samples that do not fit any class model, which is important for QC workflows. Its training node performs one fit and reports calibration diagnostics only. Validation belongs to an explicit split plan and the shared fold executor; an unassigned result is a scientific rejection, not a fabricated class prediction.

Registry reference

Generated from registered node metadata. Edit methodology and examples outside the marked section. Defaults and options below are JSON values; null means no concrete default is declared. Internal parameters are retained for contract inspection and are not scientist-editable controls. Conditional visibility describes the editor; execution admission remains node-owned.

Node Operation
Apply Fitted KNN classification.apply_knn
Apply Fitted PLS-DA classification.apply_plsda
Apply Fitted SIMCA classification.apply_simca
Train KNN Classifier classification.knn
Train PLS-DA Classifier classification.plsda
Train SIMCA Classifier classification.simca
PLS-DA Response Permutation diagnostics.plsda_permutation

Apply Fitted KNN (classification.apply_knn)

Ports

Direction Port Type URI Required Variadic Accepted data roles
input default spectrasherpa://types/Array2D/1.0 false false ["X_spectra", "X_features"]
input X_new spectrasherpa://types/Array2D/1.0 false false ["X_spectra", "X_features"]
input fitted_state spectrasherpa://types/ClassificationModel/1.0 false false []
output y_pred spectrasherpa://types/Categorical/1.0 true false []
output y_prob spectrasherpa://types/Array2D/1.0 true false []

Parameters

Parameter Editor type Required Default Options / enum Bounds / step Visibility / category Description
artifact_digest text false null — — {"category": "internal"} —
serializer text false null — — {"category": "internal"} —
source_contract_digest text false null — — {"category": "internal"} —
state_content_digest text false null — — {"category": "internal"} —
state_digest text false null — — {"category": "internal"} —
state_node_id text false null — — {"category": "internal"} —

Apply Fitted PLS-DA (classification.apply_plsda)

Ports

Direction Port Type URI Required Variadic Accepted data roles
input default spectrasherpa://types/Array2D/1.0 true false ["X_spectra", "X_features"]
input fitted_state spectrasherpa://types/ClassificationModel/1.0 false false []
output y_pred spectrasherpa://types/Categorical/1.0 true false []
output class_scores spectrasherpa://types/Array2D/1.0 true false []

Parameters

Parameter Editor type Required Default Options / enum Bounds / step Visibility / category Description
artifact_digest text false null — — {"category": "internal"} —
serializer text false null — — {"category": "internal"} —
source_contract_digest text false null — — {"category": "internal"} —
state_content_digest text false null — — {"category": "internal"} —
state_digest text false null — — {"category": "internal"} —
state_node_id text false null — — {"category": "internal"} —

Apply Fitted SIMCA (classification.apply_simca)

Ports

Direction Port Type URI Required Variadic Accepted data roles
input default spectrasherpa://types/Array2D/1.0 false false ["X_spectra", "X_features"]
input X_new spectrasherpa://types/Array2D/1.0 false false ["X_spectra", "X_features"]
input fitted_state spectrasherpa://types/ClassificationModel/1.0 false false []
output y_pred spectrasherpa://types/Categorical/1.0 true false []
output class_affinity spectrasherpa://types/Array2D/1.0 true false []

Parameters

Parameter Editor type Required Default Options / enum Bounds / step Visibility / category Description
artifact_digest text false null — — {"category": "internal"} —
serializer text false null — — {"category": "internal"} —
source_contract_digest text false null — — {"category": "internal"} —
state_content_digest text false null — — {"category": "internal"} —
state_digest text false null — — {"category": "internal"} —
state_node_id text false null — — {"category": "internal"} —

Train KNN Classifier (classification.knn)

Ports

Direction Port Type URI Required Variadic Accepted data roles
input X spectrasherpa://types/Array2D/1.0 true false ["X_spectra", "X_features"]
input y spectrasherpa://types/TargetMatrix/1.0 false false []
output default spectrasherpa://types/ScoreMatrix/1.0 true false []
output fitted_state spectrasherpa://types/ClassificationModel/1.0 true false []
output predictions spectrasherpa://types/Categorical/1.0 true false []
output probabilities spectrasherpa://types/Array2D/1.0 true false []
output class_probabilities spectrasherpa://types/Array2D/1.0 true false []
output metrics spectrasherpa://types/StatisticsSummary/1.0 false false []
output distances spectrasherpa://types/Array2D/1.0 true false []
output neighbor_indices spectrasherpa://types/Array2D/1.0 true false []
output train_accuracy spectrasherpa://types/Scalar/1.0 false false []
output plots spectrasherpa://types/Visualization/1.0 false false []
output visualization spectrasherpa://types/Visualization/1.0 true false []
output confusion_visualization spectrasherpa://types/Visualization/1.0 true false []

Parameters

Parameter Editor type Required Default Options / enum Bounds / step Visibility / category Description
n_neighbors number true 5 — {"max_value": 50, "min_value": 1, "step": 1} {"category": "basic"} Number of neighbors to consider Caps per-sample vote cardinality and returned neighbor-output width; the scientific fit also requires k not to exceed the supplied training rows.
weights select false "uniform" ["uniform", "distance"] — {"category": "basic"} Weight function: uniform (all equal) or distance (closer = more weight)
metric select false "euclidean" ["euclidean", "manhattan", "chebyshev", "minkowski"] — {"category": "basic"} Distance metric for nearest neighbor calculation
scale boolean false true — — {"category": "basic"} Standardize variables before distance calculations. Disable only when upstream scores or features are already on the intended scale.

Train PLS-DA Classifier (classification.plsda)

Ports

Direction Port Type URI Required Variadic Accepted data roles
input X spectrasherpa://types/Array2D/1.0 true false ["X_spectra", "X_features"]
input y spectrasherpa://types/TargetMatrix/1.0 false false []
output default spectrasherpa://types/ScoreMatrix/1.0 true false []
output X_scores spectrasherpa://types/ScoreMatrix/1.0 true false []
output X_loadings spectrasherpa://types/LoadingMatrix/1.0 true false []
output loadings spectrasherpa://types/LoadingMatrix/1.0 true false []
output explained_variance spectrasherpa://types/ExplainedVarianceMatrix/1.0 true false []
output class_coefficients spectrasherpa://types/RegressionCoefficientMatrix/1.0 true false []
output fitted_state spectrasherpa://types/ClassificationModel/1.0 true false []
output predictions spectrasherpa://types/Categorical/1.0 true false []
output class_scores spectrasherpa://types/Array2D/1.0 true false []
output vip_scores spectrasherpa://types/VariableImportance/1.0 true false []
output confusion_matrix_train spectrasherpa://types/ConfusionMatrix/1.0 true false []
output metrics spectrasherpa://types/StatisticsSummary/1.0 true false []
output component_curve spectrasherpa://types/ValidationResult/1.0 false false []
output sample_diagnostics spectrasherpa://types/PLSDASampleDiagnostics/1.0 false false []
output plots spectrasherpa://types/Visualization/1.0 false false []

Parameters

Parameter Editor type Required Default Options / enum Bounds / step Visibility / category Description
n_components number true 2 — {"max_value": 20, "min_value": 1, "step": 1} {"category": "basic"} Number of PLS2 latent variables Bounds latent-variable fitting and artifact size; runtime further limits components to the smallest fold-local calibration rank.
scale boolean false false — — {"category": "basic"} Fit scaling inside every calibration or validation fold

Train SIMCA Classifier (classification.simca)

Ports

Direction Port Type URI Required Variadic Accepted data roles
input X spectrasherpa://types/Array2D/1.0 true false ["X_spectra", "X_features"]
input y spectrasherpa://types/TargetMatrix/1.0 false false []
output default spectrasherpa://types/ScoreMatrix/1.0 true false []
output fitted_state spectrasherpa://types/ClassificationModel/1.0 true false []
output predictions spectrasherpa://types/Categorical/1.0 true false []
output class_assignment spectrasherpa://types/Categorical/1.0 true false []
output distances spectrasherpa://types/Any/1.0 true false []
output class_distance_matrix spectrasherpa://types/Array2D/1.0 true false []
output metrics spectrasherpa://types/StatisticsSummary/1.0 false false []
output train_accuracy spectrasherpa://types/Scalar/1.0 false false []
output confusion_matrix spectrasherpa://types/ConfusionMatrix/1.0 false false []
output plots spectrasherpa://types/Visualization/1.0 false false []
output acceptance_visualization spectrasherpa://types/Visualization/1.0 true false []
output confusion_visualization spectrasherpa://types/Visualization/1.0 true false []

Parameters

Parameter Editor type Required Default Options / enum Bounds / step Visibility / category Description
n_components number true 3 — {"max_value": 50, "min_value": 1, "step": 1} {"category": "basic"} Number of PCs for each class model Bounds per-class PCA fit and cross-validation cost in the interactive runtime.
confidence_level number false 0.95 — {"min_value": 0.8, "step": 0.01} {"category": "basic"} Confidence level for class boundaries
critical_limits_method select false "ddmoments" ["ddmoments", "classical"] — {"category": "basic"} How T² and Q critical limits are computed for class membership. 'ddmoments' (default in v0.4.3+): Pomerantsev data-driven moments (J. Chemom. 2008) — estimates effective degrees of freedom from the calibration distribution; more robust on heavy-tailed Q and small classes. 'classical': F-distribution T² + χ² Q (Nomikos & MacGregor 1995, Jackson & Mudholkar 1979) — the pre-v0.4.3 behaviour, kept for reproducibility with legacy reports.

PLS-DA Response Permutation (diagnostics.plsda_permutation)

Ports

Direction Port Type URI Required Variadic Accepted data roles
input X spectrasherpa://types/Array2D/1.0 true false []
input y spectrasherpa://types/TargetMatrix/1.0 false false []
input fitted_state spectrasherpa://types/ClassificationModel/1.0 true false []
output default spectrasherpa://types/ValidationResult/1.0 true false []

Parameters

Parameter Editor type Required Default Options / enum Bounds / step Visibility / category Description
permutations number true 19 — {"max_value": 199, "min_value": 19, "step": 1} {"category": "basic"} Bounds repeated fold-local model fits.
folds number true 3 — {"max_value": 5, "min_value": 2, "step": 1} {"category": "basic"} Preserves classes in bounded grouped folds.
maximum_components number true 5 — {"max_value": 10, "min_value": 1, "step": 1} {"category": "basic"} Bounds full component search per shuffle.
seed number true 42 — {"max_value": 4294967295, "min_value": 0, "step": 1} {"category": "basic"} Uses an exact unsigned 32-bit reproducibility seed.
block_column text false "" — — {"category": "basic"} Optional column from the verified attached sample table; never a free-standing vector.