nirs4all.visualization.chart_utils.matrix_builder module
MatrixBuilder - Build matrices for heatmap visualizations.
- class nirs4all.visualization.chart_utils.matrix_builder.MatrixBuilder[source]
Bases:
objectBuild matrices for heatmap visualizations.
Handles grouping scores by variables and creating 2D matrices with support for different aggregation strategies.
Optimized to work with PredictionResultsList from predictions.top().
- static build_matrices(score_dict: Dict, aggregation: str, higher_better: bool, natural_sort: bool = True) Tuple[List, List, ndarray, ndarray][source]
Build matrices from score dictionary.
- Parameters:
score_dict – Dict of scores grouped by x and y variables. Can be {y: {x: [scores]}} or {y: {x: (score, count)}}.
aggregation – Aggregation method (‘best’, ‘mean’, ‘median’, ‘identity’). Use ‘identity’ if scores are already aggregated tuples.
higher_better – Whether higher values are better.
natural_sort – Whether to use natural sorting for labels.
- Returns:
Tuple of (y_labels, x_labels, score_matrix, count_matrix).
- static build_score_dict(predictions_list, x_var: str, y_var: str, display_score_field: str, rank_field: str | None = None) Dict[source]
Group scores by x and y variables from PredictionResultsList.
- Parameters:
predictions_list – List of prediction results.
x_var – Variable name for x-axis grouping.
y_var – Variable name for y-axis grouping.
display_score_field – Field name for display scores.
rank_field – Optional field name for ranking scores.
- Returns:
{y_val: {x_val: [(display_score, rank_score), …]}} or {y_val: {x_val: [score1, score2, …]}} if no rank_field.
- Return type:
Dict structure
- static build_score_dict_with_dynamic_partition(predictions_list, x_var: str, y_var: str, metric: str, use_rank_scores: bool = False) Dict[source]
Group scores by x and y variables when partition is one of the grouping variables.
This method handles the special case where ‘partition’ is used as x_var or y_var. It extracts the score from the appropriate partition field based on the partition value.
- Parameters:
predictions_list – List of prediction results.
x_var – Variable name for x-axis grouping.
y_var – Variable name for y-axis grouping.
metric – Metric name to extract scores for.
use_rank_scores – If True, include rank scores for proper aggregation.
- Returns:
- {y_val: {x_val: [score1, score2, …]}} or
{y_val: {x_val: [(display_score, rank_score), …]}}
- Return type:
Dict structure