Skip to content

Commit 13bbc43

Browse files
author
Pete Luferenko
committed
Adding 'aspirational examples' and some more baseline scenarios
1 parent 89dfc82 commit 13bbc43

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<PropertyGroup>
33
<TargetFramework>netcoreapp2.0</TargetFramework>
44
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Remove="Scenarios\Api\AspirationalExamples.cs" />
7+
</ItemGroup>
58

69
<ItemGroup>
710
<ProjectReference Include="..\..\src\Microsoft.ML.Ensemble\Microsoft.ML.Ensemble.csproj" />
@@ -28,4 +31,8 @@
2831
<ItemGroup>
2932
<PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" />
3033
</ItemGroup>
34+
35+
<ItemGroup>
36+
<None Include="Scenarios\Api\AspirationalExamples.cs" />
37+
</ItemGroup>
3138
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Microsoft.ML.Tests.Scenarios.Api
6+
{
7+
public class AspirationalExamples
8+
{
9+
public class IrisPrediction
10+
{
11+
public string PredictedLabel;
12+
}
13+
14+
public class IrisData
15+
{
16+
public float[] Features;
17+
}
18+
19+
public void FirstExperienceWithML()
20+
{
21+
// This is the 'getting started with ML' example, how we see it in our new API.
22+
// It currently doesn't compile, let alone work, but we still can discuss and improve the syntax.
23+
24+
// Load the data into the system.
25+
string dataPath = "iris-data.txt";
26+
var data = TextReader.ReadFile(dataPath, c => (Label: c.LoadString(0), Features: c.LoadFloat(1, 4)));
27+
28+
// Assign numeric values to text in the "Label" column, because only
29+
// numbers can be processed during model training.
30+
var transformer = data.MakeTransformer(row => (Label: row.Label.Dictionarize(), row.Features));
31+
var trainingData = transformer.Transform(data);
32+
33+
// Train a multiclass linear classifier.
34+
var learner = new StochasticDualCoordinateAscentClassifier();
35+
var classifier = learner.Train(trainingData);
36+
37+
// Obtain some predictions.
38+
var predictionEngine = new PredictionEngine<float[], string>(classifier, inputColumn: "Features", outputColumn: "PredictedLabel");
39+
string prediction = predictionEngine.Predict(new[] { 3.3f, 1.6f, 0.2f, 5.1f });
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)