Skip to contents

Applies a previously optimized DLBCLone KNN model to predict class labels for new (test) samples. This function combines the training and test feature matrices, ensures feature compatibility, and uses the parameters from a DLBCLone KNN optimization run to classify the test samples. Optionally, runs in iterative mode for more stable results when predicting multiple samples.

Usage

DLBCLone_KNN_predict(
  train_df,
  test_df,
  metadata,
  DLBCLone_KNN_out,
  mode = "batch",
  truth_column = "lymphgen",
  other_class = "Other"
)

Arguments

train_df

Data frame or matrix of features for training samples (rows = samples, columns = features).

test_df

Data frame or matrix of features for test samples to be classified.

metadata

Data frame with metadata for all samples, including at least a sample_id column.

DLBCLone_KNN_out

List. Output from a previous call to DLBCLone_KNN containing optimized parameters. (Required)

mode

Character. If "iterative", runs KNN prediction for each test sample individually (recommended for stability).

core_features

Optional character vector of feature names to upweight in the KNN calculation.

core_feature_multiplier

Numeric. Multiplier to apply to core features (default: 1.5).

hidden_features

Optional character vector of feature names to exclude from the analysis.

Value

A list containing the KNN prediction results for the test samples, including predicted class labels and scores.

Details

  • Ensures that the feature columns in train_df and test_df are compatible.

  • If mode = "iterative", runs KNN prediction for each test sample one at a time.

  • Uses the parameters (e.g., k, feature weights) from the provided DLBCLone_KNN_out object.

  • Returns the same structure as DLBCLone_KNN, with predictions for the test samples.

Examples