-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Typed SDCA binary trainers #2506
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
018c95d
Typed SDCA binary trainers
wschin b95da3e
Fix a test
wschin d3c3a1b
Fix 3 tests where calibrated trainer should be used
wschin f8e0953
Sdca entry points also strongly-typed based on trained models.
wschin 9334bde
Rename baseline files because of change on entry point's name
wschin 84c7f7a
Update release test files
wschin 3dabf17
Update doc
wschin 267c387
Address Ivan's comments (hopefully)
wschin e2b9114
Address comments and also improve some tests
wschin 9e320ac
Fix a test
wschin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...es/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SDCASupportVectorMachine.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Linq; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public class SDCASupportVectorMachine | ||
{ | ||
public static void Example() | ||
{ | ||
// Generate IEnumerable<BinaryLabelFloatFeatureVectorSample> as training examples. | ||
var rawData = SamplesUtils.DatasetUtils.GenerateBinaryLabelFloatFeatureVectorSamples(100); | ||
|
||
// Information in first example. | ||
// Label: true | ||
Console.WriteLine("First example's label is {0}", rawData.First().Label); | ||
// Features is a 10-element float[]: | ||
// [0] 1.0173254 float | ||
// [1] 0.9680227 float | ||
// [2] 0.7581612 float | ||
// [3] 0.406033158 float | ||
// [4] 0.7588848 float | ||
// [5] 1.10602713 float | ||
// [6] 0.6421779 float | ||
// [7] 1.17754972 float | ||
// [8] 0.473704457 float | ||
// [9] 0.4919063 float | ||
Console.WriteLine("First example's feature vector is {0}", rawData.First().Features); | ||
|
||
// Create a new context for ML.NET operations. It can be used for exception tracking and logging, | ||
// as a catalog of available operations and as the source of randomness. | ||
var mlContext = new MLContext(); | ||
|
||
// Step 1: Read the data as an IDataView. | ||
var data = mlContext.Data.ReadFromEnumerable(rawData); | ||
|
||
// ML.NET doesn't cache data set by default. Caching is always recommended when using the | ||
// StochasticDualCoordinateAscent algorithm because it may incur multiple data passes. | ||
data = mlContext.Data.Cache(data); | ||
|
||
// Step 2: Create a binary classifier. This trainer may produce a logistic regression model. | ||
// We set the "Label" column as the label of the dataset, and the "Features" column as the features column. | ||
var pipeline = mlContext.BinaryClassification.Trainers.StochasticDualCoordinateAscentNonCalibrated( | ||
labelColumn: "Label", featureColumn: "Features", loss: new HingeLoss(), l2Const: 0.001f); | ||
|
||
// Step 3: Train the pipeline created. | ||
var model = pipeline.Fit(data); | ||
|
||
// Step 4: Make prediction and evaluate its quality (on training set). | ||
var prediction = model.Transform(data); | ||
|
||
var rawPrediction = mlContext.CreateEnumerable<SamplesUtils.DatasetUtils.NonCalibratedBinaryClassifierOutput>(prediction, false); | ||
|
||
// Step 5: Inspect the prediction of the first example. | ||
// Note that positive/negative label may be associated with positive/negative score | ||
var first = rawPrediction.First(); | ||
Console.WriteLine("The first example actual label is {0}. The trained model assigns it a score {1}.", | ||
first.Label /*true*/, first.Score /*around 3*/); | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
docs/samples/Microsoft.ML.Samples/Static/SDCABinaryClassification.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System; | ||
using Microsoft.ML.Data; | ||
using Microsoft.ML.StaticPipe; | ||
|
||
namespace Microsoft.ML.Samples.Static | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a static class right? (Only if you happen to post another commit after this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully #2548 can fix it.