diff --git a/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj b/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj index 7360f0f4d0..504b988f82 100644 --- a/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj +++ b/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj @@ -2,6 +2,9 @@ netcoreapp2.0 + + + @@ -28,4 +31,8 @@ + + + + \ No newline at end of file diff --git a/test/Microsoft.ML.Tests/Scenarios/Api/AspirationalExamples.cs b/test/Microsoft.ML.Tests/Scenarios/Api/AspirationalExamples.cs new file mode 100644 index 0000000000..bcb8b7d98f --- /dev/null +++ b/test/Microsoft.ML.Tests/Scenarios/Api/AspirationalExamples.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.ML.Tests.Scenarios.Api +{ + public class AspirationalExamples + { + public class IrisPrediction + { + public string PredictedLabel; + } + + public class IrisExample + { + public float SepalWidth { get; set; } + public float SepalLength { get; set; } + public float PetalWidth { get; set; } + public float PetalLength { get; set; } + } + + public void FirstExperienceWithML() + { + // This is the 'getting started with ML' example, how we see it in our new API. + // It currently doesn't compile, let alone work, but we still can discuss and improve the syntax. + + // Load the data into the system. + string dataPath = "iris-data.txt"; + var data = TextReader.FitAndRead(env, dataPath, row => ( + Label: row.ReadString(0), + SepalWidth: row.ReadFloat(1), + SepalLength: row.ReadFloat(2), + PetalWidth: row.ReadFloat(3), + PetalLength: row.ReadFloat(4))); + + + var preprocess = data.Schema.MakeEstimator(row => ( + // Convert string label to key. + Label: row.Label.DictionarizeLabel(), + // Concatenate all features into a vector. + Features: row.SepalWidth.ConcatWith(row.SepalLength, row.PetalWidth, row.PetalLength))); + + var pipeline = preprocess + // Append the trainer to the training pipeline. + .AppendEstimator(row => row.Label.PredictWithSdca(row.Features)) + .AppendEstimator(row => row.PredictedLabel.KeyToValue()); + + // Train the model and make some predictions. + var model = pipeline.Fit(data); + + IrisPrediction prediction = model.Predict(new IrisExample + { + SepalWidth = 3.3f, + SepalLength = 1.6f, + PetalWidth = 0.2f, + PetalLength = 5.1f + }); + } + } +}