Skip to main content

Training and Evaluation

This document describes how to train models with Xdows-Model-Maker and how to perform batch evaluation with Xdows-Model-Evaluator. For model architecture and feature contracts, see Architecture.

Sample Specification​

Default sample directories come from TrainingConfig:

  • Black samples (malicious): D:\Code\Model\Files\Black
  • White samples (safe): D:\Code\Model\Files\White

Files in both directories should be PE files (.exe, .dll, etc.). Sample file names do not require a specific format, but it is recommended to store them by family or source for traceability.

For Pro training, each sample may additionally carry three optional metadata fields that make the evaluation honest:

FieldPurpose
GroupKeyMalware family or campaign identifier. Samples sharing a GroupKey are kept on the same side of the split so near-duplicates cannot leak from the test set into the training set.
TimeKeySample collection time. Required when ProSplitMode is TimeOrdered.
ContentHashSHA-256 of the file content, computed by the splitter for deduplication.
Safety Notice

Do not commit real malware samples to the repository. Xdows-Model\tests\samples\README.md describes the storage and usage specification for safe samples. Black samples used for training should be placed outside the repository and excluded via .gitignore.

Training Tool​

Xdows-Model-Maker is an interactive menu tool:

dotnet run --project D:\Code\Xdows-Model\Xdows-Model-Maker

The menu has mode checkboxes plus these actions:

  • Start training (trains every checked mode in turn)
  • Start sample cleaning and statistics
  • Copy artifacts to the invoker — copies the freshly trained ONNX files, the Pro manifest, and the recommended-threshold manifests into Xdows-Model-Invoker\Models\, so the Invoker picks them up without a manual copy step
  • Exit

Pro training trains the five branch models (Standard / Flash / RawStat / Structural / ImportBehavior) in turn, uses their Out-of-Fold probabilities to train the Fusion logistic regression model, and finally outputs 6 ONNX files plus Xdows-Model-Pro.manifest.json. The artifact list is derived from ProBranches and ProModelManifest rather than hard-coded, so a newly added branch cannot be silently left out of the copy step.

Dataset Splitting​

Pro uses ProDatasetSplitter instead of a naive random split:

  1. Content-hash deduplication (ProDeduplicateByContentHash, default on) removes byte-identical samples first. Duplicates would otherwise land in both the training and the test set and inflate the reported metrics.
  2. Group isolation (ProEnforceGroupIsolation, default on) keeps every sample sharing a GroupKey entirely on one side. Samples without a GroupKey degrade to one group per sample, and the split report states plainly that group isolation was not effective.
  3. Split strategy (ProSplitMode): StratifiedRandom (default) keeps the class ratio in both halves; TimeOrdered sorts by TimeKey and puts the newest segment into the test set, and fails explicitly when a sample has no TimeKey rather than silently degrading.
  4. Report: the splitter prints the class distribution of both halves and the deduplication and isolation statistics.

The outer test fraction is ProTestFraction (default 0.2) and must lie strictly between 0 and 1.

Hyperparameters​

Key hyperparameters are defined in TrainingConfig.cs and can be modified before training:

Common​

ParameterDefaultDescription
RandomSeed43846Global random seed, ensuring reproducibility
FalsePositiveCostRatio2.65How many false negatives one false positive is worth; drives both threshold selection and sample weighting
UseCostSensitiveThresholdtrueCalibrate the recommended threshold automatically instead of using the fixed one
UseCostSensitiveTrainingWeighttruePropagate the false-positive cost into the LightGBM positive-class weight

Standard​

ParameterDefaultDescription
LearningRate0.025Learning rate
NumberOfLeaves127Number of leaves
MinimumExampleCountPerLeaf16Minimum samples per leaf node
NumberOfIterations1400Number of iterations
StandardL1Regularization0.02L1 regularization
StandardL2Regularization0.4L2 regularization
StandardMaximumTreeDepth10Maximum tree depth
StandardFeatureFraction0.9Feature sampling ratio
StandardSubsampleFraction0.85Sample subsampling ratio
StandardTargetFalsePositiveRate0.005Threshold-calibration target FPR
StandardThreshold92.0Fixed detection threshold (percentage)

Flash​

ParameterDefaultDescription
FlashLearningRate0.1Learning rate
FlashNumberOfLeaves31Number of leaves
FlashMinimumExampleCountPerLeaf8Minimum samples per leaf node
FlashNumberOfIterations800Number of iterations
FlashL1Regularization0.01L1 regularization
FlashL2Regularization0.2L2 regularization
FlashMaximumTreeDepth5Maximum tree depth
FlashThreshold96.0Fixed detection threshold (percentage)

Pro​

ParameterDefaultDescription
ProLearningRate0.01Branch learning rate
ProNumberOfLeaves63Number of leaves
ProMinimumExampleCountPerLeaf10Minimum samples per leaf node
ProNumberOfIterations1200Branch iteration count
ProL1Regularization0.01L1 regularization
ProL2Regularization0.1L2 regularization
ProMaximumTreeDepth8Maximum tree depth
ProFeatureFraction0.85Feature sampling ratio
ProSubsampleFraction0.8Sample subsampling ratio
ProMaxParallelBranches4Cap on branch parallelism
ProTestFraction0.2Outer test-set fraction
ProSplitModeStratifiedRandomStratifiedRandom or TimeOrdered
ProThreshold94.0Fixed detection threshold (percentage)

Pro's Fusion model uses logistic regression and has no independent GBDT hyperparameters.

Recommended Threshold Calibration​

Every mode ships a recommended threshold alongside its ONNX file:

  • Standard → Xdows-Model.threshold.json
  • Flash → Xdows-Model-Flash.threshold.json
  • Pro → Xdows-Model-Pro.threshold.json, mirrored into Xdows-Model-Pro.manifest.json

The value is chosen at training time with a cost-sensitive objective (one false positive is charged as FalsePositiveCostRatio false negatives) and recorded with the selection method. It defines the lower bound of the Suspicious band and never overrides the fixed threshold in TrainingConfig. The manifest is written next to both the ML.NET model and the exported ONNX file; only when UseCostSensitiveThreshold is on.

Model Output​

After training completes, model files are output to the path specified by TrainingConfig:

ModeOutput files
StandardXdows-Model.zip + Xdows-Model.onnx + Xdows-Model.threshold.json
FlashXdows-Model-Flash.zip + Xdows-Model-Flash.onnx + Xdows-Model-Flash.threshold.json
ProXdows-Model-Pro.zip + Xdows-Model-Pro.onnx + 5 branch .onnx files (-Standard, -Flash, -RawStat, -Structural, -ImportBehavior) + Xdows-Model-Pro.manifest.json + Xdows-Model-Pro.threshold.json

Pro defaults to outputting a 5-input Fusion model plus 5 branch models, and the Invoker enables the five-branch Stacking path after validating the manifest. A legacy four-branch model (4-input Fusion, 519-dimensional hybrid input, no manifest) still loads through the compatibility path; a 5143-dimensional single model without branches takes the single-model fallback path.

Use Copy artifacts to the invoker in the Maker menu to place the whole set into Xdows-Model-Invoker\Models\. The Pro model, its five branch models, and its manifest must be deployed together — a five-input Fusion model without its manifest is rejected by the Invoker.

Batch Evaluation​

Xdows-Model-Evaluator performs batch evaluation of a specified mode's model on a sample set, outputting accuracy, TPR, FPR, and average scan time, with an optional export of a misjudged-samples CSV.

dotnet run --project D:\Code\Xdows-Model\Xdows-Model-Evaluator -- --mode all --limit 700 --csv hard-cases.csv

Options​

OptionDescriptionDefault
--mode <all|standard|flash|pro>Evaluation modeall
--black <folder>Black sample directoryTrainingConfig.BlackFolder
--white <folder>White sample directoryTrainingConfig.WhiteFolder
--limit <n>Sample count per classFull set
--seed <n>Sampling seed42
--csv <path>Export only FP/FN/failed samplesNot exported
--standard-model <path>Standard ONNX pathDefault path
--flash-model <path>Flash ONNX pathDefault path
--pro-model <path>Pro ONNX pathDefault path

Output Metrics​

Each mode outputs the following metrics:

  • Accuracy: accuracy = (TP + TN) / total
  • TPR: True Positive Rate (recall) = TP / (TP + FN)
  • FPR: False Positive Rate (false-alarm rate) = FP / (FP + TN)
  • F1: F1 score = 2 × TP / (2 × TP + FP + FN)
  • AUC: Area Under the ROC Curve (conditional output)
  • AUPRC: Area Under the PR Curve (conditional output)
  • Average scan time: average inference time per file
  • Failures: number of samples that could not be evaluated due to PE validation failure, file read errors, etc.

The CSV export contains the fields mode,path,label,prediction,probability,error and records only FP, FN, and failed samples, used for troubleshooting hard cases.

Native Consistency Test​

tests\Invoke-NativeConsistency.ps1 scans the same batch of safe PE samples through both the managed caller and the native DLL for Standard, Flash, Pro, and Adaptive:

& 'D:\Code\Xdows-Model\tests\Invoke-NativeConsistency.ps1' -SkipBuild

Both sides must agree on the three-tier verdict (Clean / Suspicious / Malware) and on the threat decision, and the probability difference must stay within the configured tolerance. Because the verdict depends on the recommended threshold, the script also asserts that the required model files are present — the five Pro branch models, Xdows-Model-Pro.manifest.json, and the three *.threshold.json manifests.

After modifying the feature extraction or inference logic on either the Invoker or Native side, you must run this test once to ensure both sides reach consistent conclusions.