2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System ;
6
+ using System . Globalization ;
5
7
using System . Linq ;
8
+ using System . Threading ;
6
9
using Microsoft . ML . Data ;
7
10
using Microsoft . ML . TestFramework ;
8
11
using Microsoft . ML . TestFramework . Attributes ;
@@ -102,22 +105,55 @@ private void Context_Log(object sender, LoggingEventArgs e)
102
105
//throw new NotImplementedException();
103
106
}
104
107
105
- [ Fact ]
106
- public void AutoFitRegressionTest ( )
108
+ [ Theory ]
109
+ [ InlineData ( "en-US" ) ]
110
+ [ InlineData ( "ar-SA" ) ]
111
+ [ InlineData ( "pl-PL" ) ]
112
+ public void AutoFitRegressionTest ( string culture )
107
113
{
108
- var context = new MLContext ( 1 ) ;
109
- var dataPath = DatasetUtil . GetMlNetGeneratedRegressionDataset ( ) ;
110
- var columnInference = context . Auto ( ) . InferColumns ( dataPath , DatasetUtil . MlNetGeneratedRegressionLabel ) ;
111
- var textLoader = context . Data . CreateTextLoader ( columnInference . TextLoaderOptions ) ;
112
- var trainData = textLoader . Load ( dataPath ) ;
113
- var validationData = context . Data . TakeRows ( trainData , 20 ) ;
114
- trainData = context . Data . SkipRows ( trainData , 20 ) ;
115
- var result = context . Auto ( )
116
- . CreateRegressionExperiment ( 0 )
117
- . Execute ( trainData , validationData ,
118
- new ColumnInformation ( ) { LabelColumnName = DatasetUtil . MlNetGeneratedRegressionLabel } ) ;
114
+ var originalCulture = Thread . CurrentThread . CurrentCulture ;
115
+ try
116
+ {
117
+ Thread . CurrentThread . CurrentCulture = new CultureInfo ( culture ) ;
118
+
119
+ // If users run AutoML with a different locale, sometimes
120
+ // the sweeper encounters problems when parsing some strings.
121
+ // So testing in another culture is necessary.
122
+ // Furthermore, these issues might only occur after ~70
123
+ // iterations, so more experiment time is needed for this to
124
+ // occur.
125
+ uint experimentTime = ( uint ) ( culture == "en-US" ? 0 : 180 ) ;
126
+
127
+ var experimentSettings = new RegressionExperimentSettings { MaxExperimentTimeInSeconds = experimentTime } ;
128
+ if ( ! Environment . Is64BitProcess )
129
+ {
130
+ // LightGBM isn't available on x86 machines
131
+ experimentSettings . Trainers . Remove ( RegressionTrainer . LightGbm ) ;
132
+ }
133
+
134
+ var context = new MLContext ( 1 ) ;
135
+ var dataPath = DatasetUtil . GetMlNetGeneratedRegressionDataset ( ) ;
136
+ var columnInference = context . Auto ( ) . InferColumns ( dataPath , DatasetUtil . MlNetGeneratedRegressionLabel ) ;
137
+ var textLoader = context . Data . CreateTextLoader ( columnInference . TextLoaderOptions ) ;
138
+ var trainData = textLoader . Load ( dataPath ) ;
139
+ var validationData = context . Data . TakeRows ( trainData , 20 ) ;
140
+ trainData = context . Data . SkipRows ( trainData , 20 ) ;
141
+ var result = context . Auto ( )
142
+ . CreateRegressionExperiment ( experimentSettings )
143
+ . Execute ( trainData , validationData ,
144
+ new ColumnInformation ( ) { LabelColumnName = DatasetUtil . MlNetGeneratedRegressionLabel } ) ;
145
+
146
+ Assert . True ( result . RunDetails . Max ( i => i . ValidationMetrics . RSquared > 0.9 ) ) ;
147
+
148
+ // Ensure experimentTime allows enough iterations to fully test the internationalization code
149
+ // If the below assertion fails, increase the experiment time so the number of iterations is met
150
+ Assert . True ( culture == "en-US" || result . RunDetails . Count ( ) >= 75 , $ "RunDetails.Count() = { result . RunDetails . Count ( ) } , below 75") ;
119
151
120
- Assert . True ( result . RunDetails . Max ( i => i . ValidationMetrics . RSquared > 0.9 ) ) ;
152
+ }
153
+ finally
154
+ {
155
+ Thread . CurrentThread . CurrentCulture = originalCulture ;
156
+ }
121
157
}
122
158
123
159
[ LightGBMFact ]
@@ -351,4 +387,4 @@ private TextLoader.Options GetLoaderArgsRank(string labelColumnName, string grou
351
387
} ;
352
388
}
353
389
}
354
- }
390
+ }
0 commit comments