Skip to content

Add V1 Introspective Training Tests #2859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/Microsoft.ML.Functional.Tests/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,35 @@ public static void AssertMetricsStatistics(RegressionMetricsStatistics metrics)
AssertMetricStatistics(metrics.RSquared);
AssertMetricStatistics(metrics.LossFunction);
}

/// <summary>
/// Verify that a float array has no NaNs or infinities.
/// </summary>
/// <param name="array">An array of doubles.</param>
public static void AssertFiniteNumbers(IList<float> array, int ignoreElementAt = -1)
{
for (int i = 0; i < array.Count; i++)
{
if (i == ignoreElementAt)
continue;
Assert.False(float.IsNaN(array[i]));
Assert.False(float.IsInfinity(array[i]));
}
}

/// <summary>
/// Verify that a double array has no NaNs or infinities.
/// </summary>
/// <param name="array">An array of doubles.</param>
public static void AssertFiniteNumbers(IList<double> array, int ignoreElementAt = -1)
{
for (int i = 0; i < array.Count; i++)
{
if (i == ignoreElementAt)
continue;
Assert.False(double.IsNaN(array[i]));
Assert.False(double.IsInfinity(array[i]));
}
}
}
}
69 changes: 69 additions & 0 deletions test/Microsoft.ML.Functional.Tests/Datasets/Adult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.ML.Data;

namespace Microsoft.ML.Functional.Tests.Datasets
{
/// <summary>
/// A class for the Adult test dataset.
/// </summary>
internal sealed class Adult
{
[LoadColumn(0)]
public bool Label { get; set; }

[LoadColumn(1)]
public string WorkClass { get; set; }

[LoadColumn(2)]
public string Education { get; set; }

[LoadColumn(3)]
public string MaritalStatus { get; set; }

[LoadColumn(4)]
public string Occupation { get; set; }

[LoadColumn(5)]
public string Relationship { get; set; }

[LoadColumn(6)]
public string Ethnicity { get; set; }

[LoadColumn(7)]
public string Sex { get; set; }

[LoadColumn(8)]
public string NativeCountryRegion { get; set; }

[LoadColumn(9)]
public float Age { get; set; }

[LoadColumn(10)]
public float FinalWeight { get; set; }

[LoadColumn(11)]
public float EducationNum { get; set; }

[LoadColumn(12)]
public float CapitalGain { get; set; }

[LoadColumn(13)]
public float CapitalLoss { get; set; }

[LoadColumn(14)]
public float HoursPerWeek { get; set; }

/// <summary>
/// The list of columns commonly used as categorical features.
/// </summary>
public static readonly string[] CategoricalFeatures = new string[] { "WorkClass", "Education", "MaritalStatus", "Occupation", "Relationship", "Ethnicity", "Sex", "NativeCountryRegion" };

/// <summary>
/// The list of columns commonly used as numerical features.
/// </summary>
public static readonly string[] NumericalFeatures = new string[] { "Age", "FinalWeight", "EducationNum", "CapitalGain", "CapitalLoss", "HoursPerWeek" };
}
}
16 changes: 5 additions & 11 deletions test/Microsoft.ML.Functional.Tests/Evaluation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,11 @@ public void TrainAndEvaluateRegression()
{
var mlContext = new MLContext(seed: 1);

// Get the dataset.
var data = mlContext.Data.CreateTextLoader(TestDatasets.housing.GetLoaderColumns(),
hasHeader: TestDatasets.housing.fileHasHeader, separatorChar: TestDatasets.housing.fileSeparator)
.Load(GetDataPath(TestDatasets.housing.trainFilename));

// Create a pipeline to train on the sentiment data.
var pipeline = mlContext.Transforms.Concatenate("Features", new string[] {
"CrimesPerCapita", "PercentResidental", "PercentNonRetail", "CharlesRiver", "NitricOxides", "RoomsPerDwelling",
"PercentPre40s", "EmploymentDistance", "HighwayDistance", "TaxRate", "TeacherRatio"})
.Append(mlContext.Transforms.CopyColumns("Label", "MedianHomeValue"))
.Append(mlContext.Regression.Trainers.FastTree(new FastTreeRegressionTrainer.Options { NumberOfThreads = 1 }));
// Get the dataset
var data = mlContext.Data.LoadFromTextFile<HousingRegression>(GetDataPath(TestDatasets.housing.trainFilename), hasHeader: true);
// Create a pipeline to train on the housing data.
var pipeline = mlContext.Transforms.Concatenate("Features", HousingRegression.Features)
.Append(mlContext.Regression.Trainers.FastForest(new FastForestRegression.Options { NumberOfThreads = 1 }));

// Train the model.
var model = pipeline.Fit(data);
Expand Down
Loading