Skip to content

Commit 3580e86

Browse files
author
Rogan Carr
committed
Adding introspective training scenario tests.
1 parent 0f6972b commit 3580e86

File tree

6 files changed

+387
-213
lines changed

6 files changed

+387
-213
lines changed

test/Microsoft.ML.Functional.Tests/Common.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,20 @@ public static void AssertMetricsStatistics(RegressionMetricsStatistics metrics)
267267
AssertMetricStatistics(metrics.RSquared);
268268
AssertMetricStatistics(metrics.LossFn);
269269
}
270+
271+
/// <summary>
272+
/// Verify that a numerical array has no NaNs or infinities.
273+
/// </summary>
274+
/// <param name="array">An array of doubles.</param>
275+
public static void AssertFiniteNumbers(double[] array, int ignoreElementAt = -1)
276+
{
277+
for (int i = 0; i < array.Length; i++)
278+
{
279+
if (i == ignoreElementAt)
280+
continue;
281+
Assert.False(double.IsNaN(array[i]));
282+
Assert.True(double.IsFinite(array[i]));
283+
}
284+
}
270285
}
271286
}

test/Microsoft.ML.Functional.Tests/Evaluation.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,12 @@ public void TrainAndEvaluateRegression()
237237
{
238238
var mlContext = new MLContext(seed: 1, conc: 1);
239239

240-
// Get the dataset.
241-
var data = mlContext.Data.CreateTextLoader(TestDatasets.housing.GetLoaderColumns(),
242-
hasHeader: TestDatasets.housing.fileHasHeader, separatorChar: TestDatasets.housing.fileSeparator)
243-
.Load(GetDataPath(TestDatasets.housing.trainFilename));
240+
// Get the dataset
241+
var data = mlContext.Data.LoadFromTextFile<HousingRegression>(GetDataPath(TestDatasets.housing.trainFilename), hasHeader: true);
244242

245-
// Create a pipeline to train on the sentiment data.
246-
var pipeline = mlContext.Transforms.Concatenate("Features", new string[] {
247-
"CrimesPerCapita", "PercentResidental", "PercentNonRetail", "CharlesRiver", "NitricOxides", "RoomsPerDwelling",
248-
"PercentPre40s", "EmploymentDistance", "HighwayDistance", "TaxRate", "TeacherRatio"})
249-
.Append(mlContext.Transforms.CopyColumns("Label", "MedianHomeValue"))
250-
.Append(mlContext.Regression.Trainers.FastTree(new FastTreeRegressionTrainer.Options { NumThreads = 1 }));
243+
// Create a pipeline to train on the housing data.
244+
var pipeline = mlContext.Transforms.Concatenate("Features", HousingRegression.Features)
245+
.Append(mlContext.Regression.Trainers.FastForest(new FastForestRegression.Options { NumThreads = 1 }));
251246

252247
// Train the model.
253248
var model = pipeline.Fit(data);

0 commit comments

Comments
 (0)