Skip to content

Commit 8b1b14f

Browse files
authored
Hiding of ColumnOptions (#2959)
1 parent aea88dc commit 8b1b14f

File tree

55 files changed

+525
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+525
-283
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Normalizer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public static void Example()
5858

5959
// Composing a different pipeline if we wanted to normalize more than one column at a time.
6060
// Using log scale as the normalization mode.
61-
var multiColPipeline = ml.Transforms.Normalize(NormalizingEstimator.NormalizationMode.LogMeanVariance, new ColumnOptions[] { ("LogInduced", "Induced"), ("LogSpontaneous", "Spontaneous") });
61+
var multiColPipeline = ml.Transforms.Normalize("LogInduced", "Induced", NormalizingEstimator.NormalizationMode.LogMeanVariance)
62+
.Append(ml.Transforms.Normalize("LogSpontaneous", "Spontaneous", NormalizingEstimator.NormalizationMode.LogMeanVariance));
6263
// The transformed data.
6364
var multiColtransformer = multiColPipeline.Fit(trainData);
6465
var multiColtransformedData = multiColtransformer.Transform(trainData);

docs/samples/Microsoft.ML.Samples/Dynamic/TensorFlow/TextClassification.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ public static void Example()
6969
};
7070

7171
var model = mlContext.Transforms.Text.TokenizeIntoWords("TokenizedWords", "Sentiment_Text")
72-
.Append(mlContext.Transforms.Conversion.MapValue(lookupMap, "Words", "Ids", new ColumnOptions[] { ("VariableLenghtFeatures", "TokenizedWords") }))
72+
.Append(mlContext.Transforms.Conversion.MapValue("VariableLenghtFeatures", lookupMap,
73+
lookupMap.Schema["Words"], lookupMap.Schema["Ids"], "TokenizedWords"))
7374
.Append(mlContext.Transforms.CustomMapping(ResizeFeaturesAction, "Resize"))
7475
.Append(tensorFlowModel.ScoreTensorFlowModel(new[] { "Prediction/Softmax" }, new[] { "Features" }))
75-
.Append(mlContext.Transforms.CopyColumns(("Prediction", "Prediction/Softmax")))
76+
.Append(mlContext.Transforms.CopyColumns("Prediction", "Prediction/Softmax"))
7677
.Fit(dataView);
7778
var engine = mlContext.Model.CreatePredictionEngine<IMDBSentiment, OutputScores>(model);
7879

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ConvertToGrayScale.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public static void Example()
3636

3737
var imagesFolder = Path.GetDirectoryName(imagesDataFile);
3838
// Image loading pipeline.
39-
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageObject", "ImagePath"))
40-
.Append(mlContext.Transforms.ConvertToGrayscale(("Grayscale", "ImageObject")));
39+
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, "ImageObject", "ImagePath")
40+
.Append(mlContext.Transforms.ConvertToGrayscale("Grayscale", "ImageObject"));
4141

4242
var transformedData = pipeline.Fit(data).Transform(data);
4343

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/DnnFeaturizeImage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void Example()
4040
// Installing the Microsoft.ML.DNNImageFeaturizer packages copies the models in the
4141
// `DnnImageModels` folder.
4242
// Image loading pipeline.
43-
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageObject", "ImagePath"))
43+
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, "ImageObject", "ImagePath")
4444
.Append(mlContext.Transforms.ResizeImages("ImageObject", imageWidth: 224, imageHeight: 224))
4545
.Append(mlContext.Transforms.ExtractPixels("Pixels", "ImageObject"))
4646
.Append(mlContext.Transforms.DnnFeaturizeImage("FeaturizedImage", m => m.ModelSelector.ResNet18(mlContext, m.OutputColumn, m.InputColumn), "Pixels"));

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ExtractPixels.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void Example()
3737

3838
var imagesFolder = Path.GetDirectoryName(imagesDataFile);
3939
// Image loading pipeline.
40-
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageObject", "ImagePath"))
40+
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, "ImageObject", "ImagePath")
4141
.Append(mlContext.Transforms.ResizeImages("ImageObject", imageWidth: 100, imageHeight: 100 ))
4242
.Append(mlContext.Transforms.ExtractPixels("Pixels", "ImageObject"));
4343

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/LoadImages.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void Example()
3636

3737
var imagesFolder = Path.GetDirectoryName(imagesDataFile);
3838
// Image loading pipeline.
39-
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageReal", "ImagePath"));
39+
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, "ImageReal", "ImagePath");
4040
var transformedData = pipeline.Fit(data).Transform(data);
4141

4242
// The transformedData IDataView contains the loaded images now

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ResizeImages.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void Example()
3636

3737
var imagesFolder = Path.GetDirectoryName(imagesDataFile);
3838
// Image loading pipeline.
39-
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageReal", "ImagePath"))
39+
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, "ImageReal", "ImagePath")
4040
.Append(mlContext.Transforms.ResizeImages("ImageReal", imageWidth: 100, imageHeight: 100));
4141

4242

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Microsoft.ML.Samples.Dynamic
77
{
8-
public sealed class VectorWhitenWithColumnOptions
8+
public sealed class VectorWhitenWithOptions
99
{
1010
/// This example requires installation of additional nuget package <a href="https://www.nuget.org/packages/Microsoft.ML.Mkl.Components/">Microsoft.ML.Mkl.Components</a>.
1111
public static void Example()
@@ -39,8 +39,7 @@ public static void Example()
3939

4040

4141
// A pipeline to project Features column into white noise vector.
42-
var whiteningPipeline = ml.Transforms.VectorWhiten(new Transforms.VectorWhiteningEstimator.ColumnOptions(
43-
nameof(SamplesUtils.DatasetUtils.SampleVectorOfNumbersData.Features), kind: Transforms.WhiteningKind.PrincipalComponentAnalysis, rank: 4));
42+
var whiteningPipeline = ml.Transforms.VectorWhiten(nameof(SamplesUtils.DatasetUtils.SampleVectorOfNumbersData.Features), kind: Transforms.WhiteningKind.PrincipalComponentAnalysis, rank: 4);
4443
// The transformed (projected) data.
4544
var transformedData = whiteningPipeline.Fit(trainData).Transform(trainData);
4645
// Getting the data of the newly created column, so we can preview it.

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ReplaceMissingValues.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Microsoft.ML.Data;
5-
using static Microsoft.ML.Transforms.MissingValueReplacingEstimator.ColumnOptions;
5+
using Microsoft.ML.Transforms;
66

77
namespace Microsoft.ML.Samples.Dynamic
88
{
@@ -25,7 +25,7 @@ public static void Example()
2525
var data = mlContext.Data.LoadFromEnumerable(samples);
2626

2727
// ReplaceMissingValues is used to create a column where missing values are replaced according to the ReplacementMode.
28-
var meanPipeline = mlContext.Transforms.ReplaceMissingValues("MissingReplaced", "Features", ReplacementMode.Mean);
28+
var meanPipeline = mlContext.Transforms.ReplaceMissingValues("MissingReplaced", "Features", MissingValueReplacingEstimator.ReplacementMode.Mean);
2929

3030
// Now we can transform the data and look at the output to confirm the behavior of the estimator.
3131
// This operation doesn't actually evaluate data until we read the data below.
@@ -36,7 +36,7 @@ public static void Example()
3636
var meanRowEnumerable = mlContext.Data.CreateEnumerable<SampleDataTransformed>(meanTransformedData, reuseRowObject: false);
3737

3838
// ReplaceMissingValues is used to create a column where missing values are replaced according to the ReplacementMode.
39-
var defaultPipeline = mlContext.Transforms.ReplaceMissingValues("MissingReplaced", "Features", ReplacementMode.DefaultValue);
39+
var defaultPipeline = mlContext.Transforms.ReplaceMissingValues("MissingReplaced", "Features", MissingValueReplacingEstimator.ReplacementMode.DefaultValue);
4040

4141
// Now we can transform the data and look at the output to confirm the behavior of the estimator.
4242
// This operation doesn't actually evaluate data until we read the data below.

docs/samples/Microsoft.ML.Samples/Dynamic/ValueMapping.cs

+7-17
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,14 @@ public static void Example()
3737
// 35.0 1.0 6-11yrs 1.0 3.0 32.0 5.0 ...
3838

3939
// If the list of keys and values are known, they can be passed to the API. The ValueMappingEstimator can also get the mapping through an IDataView
40-
// Creating a list of keys based on the Education values from the dataset.
41-
var educationKeys = new List<string>()
42-
{
43-
"0-5yrs",
44-
"6-11yrs",
45-
"12+yrs"
46-
};
47-
48-
// Creating a list of associated values that will map respectively to each educationKey
49-
var educationValues = new List<string>()
50-
{
51-
"Undergraduate",
52-
"Postgraduate",
53-
"Postgraduate"
54-
};
55-
40+
// Creating a list of key-value pairs based on the Education values from the dataset.
41+
var educationMap = new Dictionary<string, string> ();
42+
educationMap["0-5yrs"] = "Undergraduate";
43+
educationMap["6-11yrs"] = "Postgraduate";
44+
educationMap["12+yrs"] = "Postgraduate";
45+
5646
// Constructs the ValueMappingEstimator making the ML.net pipeline
57-
var pipeline = mlContext.Transforms.Conversion.MapValue(educationKeys, educationValues, ("EducationCategory", "Education"));
47+
var pipeline = mlContext.Transforms.Conversion.MapValue("EducationCategory", educationMap, "Education");
5848

5949
// Fits the ValueMappingEstimator and transforms the data converting the Education to EducationCategory.
6050
IDataView transformedData = pipeline.Fit(trainData).Transform(trainData);

docs/samples/Microsoft.ML.Samples/Dynamic/ValueMappingFloatToString.cs

+6-16
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,14 @@ public static void Example()
2828
IDataView trainData = mlContext.Data.LoadFromEnumerable(data);
2929

3030
// If the list of keys and values are known, they can be passed to the API. The ValueMappingEstimator can also get the mapping through an IDataView
31-
// Creating a list of keys based on the induced value from the dataset
32-
var temperatureKeys = new List<float>()
33-
{
34-
36.0f,
35-
35.0f,
36-
34.0f
37-
};
38-
39-
// Creating a list of values, these strings will map accordingly to each key.
40-
var classificationValues = new List<string>()
41-
{
42-
"T1",
43-
"T2",
44-
"T3"
45-
};
31+
// Creating a list of key-value pairs based on the induced value from the dataset
32+
var temperatureMap = new Dictionary<float, string>();
33+
temperatureMap[36.0f] = "T1";
34+
temperatureMap[35.0f] = "T2";
35+
temperatureMap[34.0f] = "T3";
4636

4737
// Constructs the ValueMappingEstimator making the ML.net pipeline
48-
var pipeline = mlContext.Transforms.Conversion.MapValue(temperatureKeys, classificationValues, ("TemperatureCategory", "Temperature"));
38+
var pipeline = mlContext.Transforms.Conversion.MapValue("TemperatureCategory", temperatureMap, "Temperature");
4939

5040
// Fits the ValueMappingEstimator and transforms the data adding the TemperatureCategory column.
5141
IDataView transformedData = pipeline.Fit(trainData).Transform(trainData);

docs/samples/Microsoft.ML.Samples/Dynamic/ValueMappingStringToArray.cs

+6-16
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,14 @@ public static void Example()
3131
IDataView trainData = mlContext.Data.LoadFromEnumerable(data);
3232

3333
// If the list of keys and values are known, they can be passed to the API. The ValueMappingEstimator can also get the mapping through an IDataView
34-
// Creating a list of keys based on the Education values from the dataset
35-
var educationKeys = new List<string>()
36-
{
37-
"0-5yrs",
38-
"6-11yrs",
39-
"12+yrs"
40-
};
41-
42-
// Sample list of associated array values
43-
var educationValues = new List<int[]>()
44-
{
45-
new int[] { 1,2,3 },
46-
new int[] { 5,6,7 },
47-
new int[] { 42,32,64 }
48-
};
34+
// Creating a list of key-value pairs based on the Education values from the dataset
35+
var educationMap = new Dictionary<string, int[]>();
36+
educationMap["0-5yrs"] = new int[] { 1, 2, 3 };
37+
educationMap["6-11yrs"] = new int[] { 5, 6, 7 };
38+
educationMap["12+yrs"] = new int[] { 42, 32, 64 };
4939

5040
// Constructs the ValueMappingEstimator making the ML.net pipeline
51-
var pipeline = mlContext.Transforms.Conversion.MapValue<string, int>(educationKeys, educationValues, ("EducationFeature", "Education"));
41+
var pipeline = mlContext.Transforms.Conversion.MapValue<string, int>("EducationFeature", educationMap, "Education");
5242

5343
// Fits the ValueMappingEstimator and transforms the data adding the EducationFeature column.
5444
IDataView transformedData = pipeline.Fit(trainData).Transform(trainData);

docs/samples/Microsoft.ML.Samples/Dynamic/ValueMappingStringToKeyType.cs

+7-17
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,18 @@ public static void Example()
3434
IEnumerable<SamplesUtils.DatasetUtils.SampleInfertData> data = SamplesUtils.DatasetUtils.GetInfertData();
3535
IDataView trainData = mlContext.Data.LoadFromEnumerable(data);
3636

37-
// Creating a list of keys based on the Education values from the dataset
37+
// Creating a list of key-value pairs based on the Education values from the dataset
3838
// These lists are created by hand for the demonstration, but the ValueMappingEstimator does take an IEnumerable.
39-
var educationKeys = new List<string>()
40-
{
41-
"0-5yrs",
42-
"6-11yrs",
43-
"12+yrs"
44-
};
45-
46-
// Creating a list of values that are sample strings. These will be converted to KeyTypes
47-
var educationValues = new List<string>()
48-
{
49-
"Undergraduate",
50-
"Postgraduate",
51-
"Postgraduate"
52-
};
39+
var educationMap = new Dictionary<string, string>();
40+
educationMap["0-5yrs"] = "Undergraduate";
41+
educationMap["6-11yrs"] = "Postgraduate";
42+
educationMap["12+yrs"] = "Postgraduate";
5343

5444
// Generate the ValueMappingEstimator that will output KeyTypes even though our values are strings.
5545
// The KeyToValueMappingEstimator is added to provide a reverse lookup of the KeyType, converting the KeyType value back
5646
// to the original value.
57-
var pipeline = mlContext.Transforms.Conversion.MapValue<string, string>(educationKeys, educationValues, true, ("EducationKeyType", "Education"))
58-
.Append(mlContext.Transforms.Conversion.MapKeyToValue(("EducationCategory", "EducationKeyType")));
47+
var pipeline = mlContext.Transforms.Conversion.MapValue("EducationKeyType", educationMap, "Education", true)
48+
.Append(mlContext.Transforms.Conversion.MapKeyToValue("EducationCategory", "EducationKeyType"));
5949

6050
// Fits the ValueMappingEstimator and transforms the data adding the EducationKeyType column.
6151
IDataView transformedData = pipeline.Fit(trainData).Transform(trainData);

0 commit comments

Comments
 (0)