-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Sample for ConvertType transform estimator #2781
Changes from 2 commits
11b9448
5793031
2ea495f
0d3d77b
992ce17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public static class ConvertTypeTransform | ||
{ | ||
private sealed class InputData | ||
{ | ||
public bool Survived; | ||
} | ||
|
||
private sealed class TransformedData | ||
{ | ||
public bool Survived { get; set; } | ||
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.
do those need to be properties? #Resolved 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. setting it to properties helps me get away with warning about uninitialized field In reply to: 261046835 [](ancestors = 261046835) |
||
|
||
public Int32 SurvivedInt32 { get; set; } | ||
} | ||
|
||
public static void Example() | ||
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.
the sample needs to be linked from the actual source it illustrates. Checkout the node on the other extension methods. #Resolved 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. |
||
{ | ||
var mlContext = new MLContext(seed: 1, conc: 1); | ||
var rawData = new[] { | ||
new InputData() { Survived = true }, | ||
new InputData() { Survived = false }, | ||
new InputData() { Survived = true }, | ||
new InputData() { Survived = false }, | ||
new InputData() { Survived = false }, | ||
}; | ||
|
||
var data = mlContext.Data.LoadFromEnumerable(rawData); | ||
|
||
// Construct the pipeline. | ||
var pipeline = mlContext.Transforms.Conversion.ConvertType("SurvivedInt32", "Survived", DataKind.Int32); | ||
|
||
// Let's train our pipeline, and then apply it to the same data. | ||
var transformer = pipeline.Fit(data); | ||
var transformedData = transformer.Transform(data); | ||
|
||
// Display original column 'Survived' (boolean) and converted column 'SurvivedInt32' (Int32) | ||
var convertedData = mlContext.Data.CreateEnumerable<TransformedData>(transformedData, true); | ||
foreach (var item in convertedData) | ||
{ | ||
Console.WriteLine("A:{0} Aconv:{1}", item.Survived, item.SurvivedInt32); | ||
} | ||
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. Put in comments the output of this WriteLine. #Resolved 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. |
||
} | ||
} | ||
} |
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.
Please rename this to ConvertType (identical to the API extension method that it correspond to) #Resolved