66using Microsoft . ML . Runtime . Api ;
77using Microsoft . ML . Runtime . Data ;
88using Microsoft . ML . Runtime . EntryPoints ;
9+ using Microsoft . ML . Runtime . Internal . Utilities ;
910using System ;
1011using System . Collections . Generic ;
1112using System . IO ;
@@ -29,6 +30,39 @@ internal Runtime.EntryPoints.TransformModel PredictorModel
2930 get { return _predictorModel ; }
3031 }
3132
33+ /// <summary>
34+ /// Returns labels that correspond to indices of the score array in the case of
35+ /// multi-class classification problem.
36+ /// </summary>
37+ /// <param name="names">Label to score mapping</param>
38+ /// <param name="scoreColumnName">Name of the score column</param>
39+ /// <returns></returns>
40+ public bool TryGetScoreLabelNames ( out string [ ] names , string scoreColumnName = DefaultColumnNames . Score )
41+ {
42+ names = null ;
43+ ISchema schema = _predictorModel . OutputSchema ;
44+ int colIndex = - 1 ;
45+ if ( ! schema . TryGetColumnIndex ( scoreColumnName , out colIndex ) )
46+ return false ;
47+
48+ int expectedLabelCount = schema . GetColumnType ( colIndex ) . ValueCount ;
49+ if ( ! schema . HasSlotNames ( colIndex , expectedLabelCount ) )
50+ return false ;
51+
52+ VBuffer < DvText > labels = default ;
53+ schema . GetMetadata ( MetadataUtils . Kinds . SlotNames , colIndex , ref labels ) ;
54+
55+ if ( labels . Length != expectedLabelCount )
56+ return false ;
57+
58+ names = new string [ expectedLabelCount ] ;
59+ int index = 0 ;
60+ foreach ( var label in labels . DenseValues ( ) )
61+ names [ index ++ ] = label . ToString ( ) ;
62+
63+ return true ;
64+ }
65+
3266 /// <summary>
3367 /// Read model from file asynchronously.
3468 /// </summary>
0 commit comments