Skip to content
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

Merged
merged 5 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/samples/Microsoft.ML.Samples/Dynamic/ConvertType.cs
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
Copy link

@shmoradims shmoradims Mar 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConvertTypeTransform [](start = 24, length = 20)

Please rename this to ConvertType (identical to the API extension method that it correspond to) #Resolved

{
private sealed class InputData
{
public bool Survived;
}

private sealed class TransformedData
{
public bool Survived { get; set; }
Copy link
Member

@sfilipi sfilipi Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ get; set; } [](start = 33, length = 13)

do those need to be properties? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The 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()
Copy link
Member

@sfilipi sfilipi Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example [](start = 27, length = 7)

the sample needs to be linked from the actual source it illustrates.

Checkout the node on the other extension methods. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 261047048 [](ancestors = 261047048)

{
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);
}
Copy link
Member

@sfilipi sfilipi Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put in comments the output of this WriteLine. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 261046921 [](ancestors = 261046921)

}
}
}
8 changes: 4 additions & 4 deletions src/Microsoft.ML.Data/Data/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,10 +1642,10 @@ public void Convert(in TX src, ref SB dst)
#endregion FromTX

#region FromBL
public void Convert(in BL src, ref I1 dst) => dst = (I1)(object)src;
public void Convert(in BL src, ref I2 dst) => dst = (I2)(object)src;
public void Convert(in BL src, ref I4 dst) => dst = (I4)(object)src;
public void Convert(in BL src, ref I8 dst) => dst = (I8)(object)src;
public void Convert(in BL src, ref I1 dst) => dst = System.Convert.ToSByte(src);
public void Convert(in BL src, ref I2 dst) => dst = System.Convert.ToInt16(src);
public void Convert(in BL src, ref I4 dst) => dst = System.Convert.ToInt32(src);
public void Convert(in BL src, ref I8 dst) => dst = System.Convert.ToInt64(src);
public void Convert(in BL src, ref R4 dst) => dst = System.Convert.ToSingle(src);
public void Convert(in BL src, ref R8 dst) => dst = System.Convert.ToDouble(src);
public void Convert(in BL src, ref BL dst) => dst = src;
Expand Down