99using Microsoft . ML . Calibrators ;
1010using Microsoft . ML . Data ;
1111using Microsoft . ML . RunTests ;
12+ using Microsoft . ML . TestFramework ;
1213using Microsoft . ML . Trainers . FastTree ;
1314using Xunit ;
15+ using Xunit . Abstractions ;
1416
15- namespace Microsoft . ML . Tests . Scenarios . Api
17+ namespace Microsoft . ML . Functional . Tests
1618{
17- public partial class ApiScenariosTests
19+ public partial class ModelLoadingTests : BaseTestClass
1820 {
21+ public ModelLoadingTests ( ITestOutputHelper output ) : base ( output )
22+ {
23+ }
24+
1925 private class InputData
2026 {
2127 [ LoadColumn ( 0 ) ]
22- public float Label { get ; set ; }
28+ public bool Label { get ; set ; }
2329 [ LoadColumn ( 9 , 14 ) ]
2430 [ VectorType ( 6 ) ]
2531 public float [ ] Features { get ; set ; }
@@ -35,23 +41,38 @@ public void LoadModelAndExtractPredictor()
3541
3642 // Pipeline.
3743 var pipeline = ml . BinaryClassification . Trainers . GeneralizedAdditiveModels ( ) ;
38-
44+ // Define the same pipeline starting with the loader.
45+ var pipeline1 = loader . Append ( ml . BinaryClassification . Trainers . GeneralizedAdditiveModels ( ) ) ;
46+
3947 // Train.
4048 var model = pipeline . Fit ( data ) ;
49+ var model1 = pipeline1 . Fit ( file ) ;
4150
4251 // Save and reload.
4352 string modelPath = GetOutputPath ( FullTestName + "-model.zip" ) ;
4453 using ( var fs = File . Create ( modelPath ) )
4554 ml . Model . Save ( data . Schema , model , fs ) ;
55+ string modelPath1 = GetOutputPath ( FullTestName + "-model1.zip" ) ;
56+ using ( var fs = File . Create ( modelPath1 ) )
57+ ml . Model . Save ( model1 , fs ) ;
4658
4759 ITransformer loadedModel ;
60+ IDataLoader < IMultiStreamSource > loadedModel1 ;
4861 using ( var fs = File . OpenRead ( modelPath ) )
4962 loadedModel = ml . Model . Load ( fs , out var loadedSchema ) ;
63+ using ( var fs = File . OpenRead ( modelPath1 ) )
64+ loadedModel1 = ml . Model . Load ( fs ) ;
5065
5166 var gam = ( ( loadedModel as ISingleFeaturePredictionTransformer < object > ) . Model
5267 as CalibratedModelParametersBase ) . SubModel
5368 as BinaryClassificationGamModelParameters ;
5469 Assert . NotNull ( gam ) ;
70+
71+ gam = ( ( ( loadedModel1 as CompositeDataLoader < IMultiStreamSource , ITransformer > ) . Transformer . LastTransformer
72+ as ISingleFeaturePredictionTransformer < object > ) . Model
73+ as CalibratedModelParametersBase ) . SubModel
74+ as BinaryClassificationGamModelParameters ;
75+ Assert . NotNull ( gam ) ;
5576 }
5677
5778 [ Fact ]
0 commit comments