@@ -24,9 +24,10 @@ public void TrainerGeneratorBasicNamedParameterTest()
24
24
PipelineNode node = new PipelineNode ( "LightGbmBinary" , PipelineNodeType . Trainer , new string [ ] { "Label" } , default ( string ) , elementProperties ) ;
25
25
Pipeline pipeline = new Pipeline ( new PipelineNode [ ] { node } ) ;
26
26
CodeGenerator codeGenerator = new CodeGenerator ( pipeline , null ) ;
27
- var actual = codeGenerator . GenerateTrainer ( ) ;
27
+ var actual = codeGenerator . GenerateTrainerAndUsings ( ) ;
28
28
string expected = "LightGbm(learningRate:0.1f,numLeaves:1,labelColumn:\" Label\" ,featureColumn:\" Features\" );" ;
29
- Assert . AreEqual ( expected , actual ) ;
29
+ Assert . AreEqual ( expected , actual . Item1 ) ;
30
+ Assert . IsNull ( actual . Item2 ) ;
30
31
}
31
32
32
33
[ TestMethod ]
@@ -43,9 +44,11 @@ public void TrainerGeneratorBasicAdvancedParameterTest()
43
44
PipelineNode node = new PipelineNode ( "LightGbmBinary" , PipelineNodeType . Trainer , new string [ ] { "Label" } , default ( string ) , elementProperties ) ;
44
45
Pipeline pipeline = new Pipeline ( new PipelineNode [ ] { node } ) ;
45
46
CodeGenerator codeGenerator = new CodeGenerator ( pipeline , null ) ;
46
- var actual = codeGenerator . GenerateTrainer ( ) ;
47
- string expected = "LightGbm(new LightGbm.Options(){LearningRate=0.1f,NumLeaves=1,UseSoftmax=true,LabelColumn=\" Label\" ,FeatureColumn=\" Features\" });" ;
48
- Assert . AreEqual ( expected , actual ) ;
47
+ var actual = codeGenerator . GenerateTrainerAndUsings ( ) ;
48
+ string expectedTrainer = "LightGbm(new Options(){LearningRate=0.1f,NumLeaves=1,UseSoftmax=true,LabelColumn=\" Label\" ,FeatureColumn=\" Features\" });" ;
49
+ string expectedUsing = "using Microsoft.ML.LightGBM;\r \n " ;
50
+ Assert . AreEqual ( expectedTrainer , actual . Item1 ) ;
51
+ Assert . AreEqual ( expectedUsing , actual . Item2 ) ;
49
52
}
50
53
51
54
[ TestMethod ]
@@ -56,9 +59,25 @@ public void TransformGeneratorBasicTest()
56
59
PipelineNode node = new PipelineNode ( "Normalizing" , PipelineNodeType . Transform , new string [ ] { "Label" } , new string [ ] { "Label" } , elementProperties ) ;
57
60
Pipeline pipeline = new Pipeline ( new PipelineNode [ ] { node } ) ;
58
61
CodeGenerator codeGenerator = new CodeGenerator ( pipeline , null ) ;
59
- var actual = codeGenerator . GenerateTransforms ( ) ;
62
+ var actual = codeGenerator . GenerateTransformsAndUsings ( ) ;
60
63
string expected = "Normalize(\" Label\" ,\" Label\" )" ;
61
- Assert . AreEqual ( expected , actual [ 0 ] ) ;
64
+ Assert . AreEqual ( expected , actual [ 0 ] . Item1 ) ;
65
+ Assert . IsNull ( actual [ 0 ] . Item2 ) ;
66
+ }
67
+
68
+ [ TestMethod ]
69
+ public void TransformGeneratorUsingTest ( )
70
+ {
71
+ var context = new MLContext ( ) ;
72
+ var elementProperties = new Dictionary < string , object > ( ) ;
73
+ PipelineNode node = new PipelineNode ( "OneHotEncoding" , PipelineNodeType . Transform , new string [ ] { "Label" } , new string [ ] { "Label" } , elementProperties ) ;
74
+ Pipeline pipeline = new Pipeline ( new PipelineNode [ ] { node } ) ;
75
+ CodeGenerator codeGenerator = new CodeGenerator ( pipeline , null ) ;
76
+ var actual = codeGenerator . GenerateTransformsAndUsings ( ) ;
77
+ string expectedTransform = "Categorical.OneHotEncoding(new []{new OneHotEncodingEstimator.ColumnInfo(\" Label\" ,\" Label\" )})" ;
78
+ var expectedUsings = "using Microsoft.ML.Transforms.Categorical;\r \n " ;
79
+ Assert . AreEqual ( expectedTransform , actual [ 0 ] . Item1 ) ;
80
+ Assert . AreEqual ( expectedUsings , actual [ 0 ] . Item2 ) ;
62
81
}
63
82
64
83
[ TestMethod ]
@@ -79,19 +98,6 @@ public void ClassLabelGenerationBasicTest()
79
98
Assert . AreEqual ( expected2 , actual [ 1 ] ) ;
80
99
}
81
100
82
- [ TestMethod ]
83
- public void GenerateUsingsBasicTest ( )
84
- {
85
- var context = new MLContext ( ) ;
86
- var elementProperties = new Dictionary < string , object > ( ) ;
87
- PipelineNode node = new PipelineNode ( "TypeConverting" , PipelineNodeType . Transform , new string [ ] { "Label" } , new string [ ] { "Label" } , elementProperties ) ;
88
- Pipeline pipeline = new Pipeline ( new PipelineNode [ ] { node } ) ;
89
- CodeGenerator codeGenerator = new CodeGenerator ( pipeline , null ) ;
90
- var actual = codeGenerator . GenerateUsings ( ) ;
91
- string expected = "using Microsoft.ML.Transforms.Conversions;\r \n " ;
92
- Assert . AreEqual ( expected , actual ) ;
93
- }
94
-
95
101
[ TestMethod ]
96
102
public void ColumnGenerationTest ( )
97
103
{
@@ -122,14 +128,16 @@ public void TrainerComplexParameterTest()
122
128
123
129
var elementProperties = new Dictionary < string , object > ( )
124
130
{
125
- { "TreeBooster " , new CustomProperty ( ) { Properties = new Dictionary < string , object > ( ) , Name = "TreeBooster" } } ,
131
+ { "Booster " , new CustomProperty ( ) { Properties = new Dictionary < string , object > ( ) , Name = "TreeBooster" } } ,
126
132
} ;
127
133
PipelineNode node = new PipelineNode ( "LightGbmBinary" , PipelineNodeType . Trainer , new string [ ] { "Label" } , default ( string ) , elementProperties ) ;
128
134
Pipeline pipeline = new Pipeline ( new PipelineNode [ ] { node } ) ;
129
135
CodeGenerator codeGenerator = new CodeGenerator ( pipeline , null ) ;
130
- var actual = codeGenerator . GenerateTrainer ( ) ;
131
- string expected = "LightGbm(new LightGbm.Options(){TreeBooster=new TreeBooster(){},LabelColumn=\" Label\" ,FeatureColumn=\" Features\" });" ;
132
- Assert . AreEqual ( expected , actual ) ;
136
+ var actual = codeGenerator . GenerateTrainerAndUsings ( ) ;
137
+ string expectedTrainer = "LightGbm(new Options(){Booster=new TreeBooster(){},LabelColumn=\" Label\" ,FeatureColumn=\" Features\" });" ;
138
+ var expectedUsings = "using Microsoft.ML.LightGBM;\r \n " ;
139
+ Assert . AreEqual ( expectedTrainer , actual . Item1 ) ;
140
+ Assert . AreEqual ( expectedUsings , actual . Item2 ) ;
133
141
134
142
}
135
143
0 commit comments