Class FoldResult<T, TInput, TOutput>
Represents the results of a single fold in cross-validation.
public class FoldResult<T, TInput, TOutput>
Type Parameters
TThe numeric type used for calculations (e.g., float, double).
TInputThe type of input data (e.g., Matrix<T> for tabular data, Tensor<T> for images).
TOutputThe type of output data (e.g., Vector<T> for predictions, custom types for other formats).
- Inheritance
-
FoldResult<T, TInput, TOutput>
- Inherited Members
Remarks
For Beginners: A FoldResult contains all the performance metrics for one "fold" in cross-validation. Think of it like a report card for a single test of your model, where the model was trained on one subset of your data and tested on another.
Constructors
FoldResult(int, Vector<T>, Vector<T>, Vector<T>, Vector<T>, Dictionary<string, T>?, TimeSpan?, TimeSpan?, int, IFullModel<T, TInput, TOutput>?, ClusteringMetrics<T>?, int[]?, int[]?)
Creates a new instance of the FoldResult class.
public FoldResult(int foldIndex, Vector<T> trainingActual, Vector<T> trainingPredicted, Vector<T> validationActual, Vector<T> validationPredicted, Dictionary<string, T>? featureImportance = null, TimeSpan? trainingTime = null, TimeSpan? evaluationTime = null, int featureCount = 0, IFullModel<T, TInput, TOutput>? model = null, ClusteringMetrics<T>? clusteringMetrics = null, int[]? trainingIndices = null, int[]? validationIndices = null)
Parameters
foldIndexintThe index of this fold.
trainingActualVector<T>The actual values in the training dataset.
trainingPredictedVector<T>The predicted values for the training dataset.
validationActualVector<T>The actual values in the validation dataset.
validationPredictedVector<T>The predicted values for the validation dataset.
featureImportanceDictionary<string, T>Optional dictionary of feature importance scores.
trainingTimeTimeSpan?Time taken to train the model.
evaluationTimeTimeSpan?Time taken to evaluate the model.
featureCountintThe number of features used in the model.
modelIFullModel<T, TInput, TOutput>Optional trained model instance for this fold.
clusteringMetricsClusteringMetrics<T>Optional clustering quality metrics for this fold.
trainingIndicesint[]Optional array of indices for training samples in this fold.
validationIndicesint[]Optional array of indices for validation samples in this fold.
Remarks
For Beginners: This constructor creates a complete report of how well your model performed on one fold of cross-validation. It calculates various error metrics and statistics that help you understand your model's strengths and weaknesses. If your model performs clustering, you can also include clustering-specific metrics.
Properties
ActualValues
Gets the actual values from the validation dataset.
public Vector<T> ActualValues { get; }
Property Value
- Vector<T>
ClusteringMetrics
Gets the clustering quality metrics for this fold, if applicable.
public ClusteringMetrics<T>? ClusteringMetrics { get; }
Property Value
Remarks
For Beginners: This property stores clustering quality metrics when your model produces cluster assignments (like K-Means, DBSCAN, or other clustering algorithms). These metrics help you understand how well the clustering performed for this specific fold:
- Silhouette Score: How well each point fits in its cluster
- Calinski-Harabasz Index: How well-separated and compact clusters are
- Davies-Bouldin Index: Average similarity between clusters (lower is better)
- Adjusted Rand Index: Similarity to ground truth labels (if available)
This property will be null if:
- The model doesn't produce cluster labels (e.g., regression or standard classification)
- Clustering metrics couldn't be calculated for this fold
When cross-validating clustering algorithms, these metrics are automatically calculated for each fold, allowing you to see how consistent your clustering is across different data splits.
EvaluationTime
Gets the time taken to evaluate the model for this fold.
public TimeSpan EvaluationTime { get; }
Property Value
FeatureImportance
Gets the feature importance scores for this fold.
public Dictionary<string, T> FeatureImportance { get; }
Property Value
- Dictionary<string, T>
FoldIndex
Gets the index of this fold in the cross-validation process.
public int FoldIndex { get; }
Property Value
Model
Gets the trained model instance for this fold.
public IFullModel<T, TInput, TOutput>? Model { get; }
Property Value
- IFullModel<T, TInput, TOutput>
Remarks
For Beginners: This property stores the model that was trained specifically on this fold's training data. Having access to the individual fold models allows you to: - Analyze how different models vary across folds - Use ensemble methods by combining predictions from multiple fold models - Investigate which features are important in different data subsets
PredictedValues
Gets the predicted values for the validation dataset.
public Vector<T> PredictedValues { get; }
Property Value
- Vector<T>
TrainingErrors
Gets the error statistics for the training data.
public ErrorStats<T> TrainingErrors { get; }
Property Value
- ErrorStats<T>
TrainingIndices
Gets the indices of the training samples in this fold.
public int[]? TrainingIndices { get; }
Property Value
- int[]
Remarks
For Beginners: These are the row indices from the original dataset that were used for training the model in this fold. For example, if this contains [0, 1, 5, 6], it means rows 0, 1, 5, and 6 from the original data were used for training.
This is especially useful for: - Nested cross-validation where you need to extract subsets based on indices - Debugging to verify correct data splits - Advanced techniques like stratified sampling verification
TrainingTime
Gets the time taken to train the model for this fold.
public TimeSpan TrainingTime { get; }
Property Value
ValidationErrors
Gets the error statistics for the validation data.
public ErrorStats<T> ValidationErrors { get; }
Property Value
- ErrorStats<T>
ValidationIndices
Gets the indices of the validation samples in this fold.
public int[]? ValidationIndices { get; }
Property Value
- int[]
Remarks
For Beginners: These are the row indices from the original dataset that were held out for validation in this fold. For example, if this contains [2, 3, 4], it means rows 2, 3, and 4 from the original data were used for validation (testing).
This ensures you can accurately reconstruct which samples were used for validation, even when the target values contain duplicates. This prevents data leakage and ensures correct nested cross-validation.
ValidationPredictionStats
Gets the prediction statistics for the validation data.
public PredictionStats<T> ValidationPredictionStats { get; }