-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Updated xml docs for tree-based trainers. #2970
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic.Trainers.Regression | ||
{ | ||
public static class FastTree | ||
{ | ||
// This example requires installation of additional NuGet package | ||
// <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>. | ||
public static void Example() | ||
{ | ||
// 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. | ||
// Setting the seed to a fixed number in this example to make outputs deterministic. | ||
var mlContext = new MLContext(seed: 0); | ||
|
||
// Create a list of training examples. | ||
var examples = GenerateRandomDataPoints(1000); | ||
|
||
// Convert the examples list to an IDataView object, which is consumable by ML.NET API. | ||
var data = mlContext.Data.LoadFromEnumerable(examples); | ||
|
||
// Define the trainer. | ||
var pipeline = mlContext.BinaryClassification.Trainers.FastTree(); | ||
|
||
// Train the model. | ||
var model = pipeline.Fit(data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is minimal version without prediction. I personally like to see in-memory prediction, which is what will happen immediately in production. Why in-memory prediction is important? |
||
} | ||
|
||
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count) | ||
{ | ||
var random = new Random(0); | ||
float randomFloat() => (float)random.NextDouble(); | ||
for (int i = 0; i < count; i++) | ||
{ | ||
var label = randomFloat(); | ||
yield return new DataPoint | ||
{ | ||
Label = label, | ||
// Create random features that are correlated with label. | ||
Features = Enumerable.Repeat(label, 50).Select(x => x + randomFloat()).ToArray() | ||
}; | ||
} | ||
} | ||
|
||
private class DataPoint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really good! An example with 50 features! |
||
{ | ||
public float Label { get; set; } | ||
[VectorType(50)] | ||
public float[] Features { get; set; } | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
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.
So do we need a Binary and Ranking examples for FastTree? #Resolved
Uh oh!
There was an error while loading. Please reload this page.
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.
all the samples will come in my next PR. I added this one as template for discussion. please see my email about in-memory samples.
In reply to: 265818226 [](ancestors = 265818226)