Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
..updating..
  • Loading branch information
singlis committed Feb 1, 2019
commit a50a29f086c693ca4c8d8000d3c702e1edee6ba2
2 changes: 1 addition & 1 deletion docs/samples/Microsoft.ML.Samples/Dynamic/ValueMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SampleInfertDataWithFeatures
}

/// This example demonstrates the use of the ValueMappingEstimator by mapping string-to-string values. This is useful
/// to map strings to a grouping. In this example, the Education data maps to the groups Undergraduate and Postgraduate:
/// to map strings to a grouping. In this example, the education data maps to the groups Undergraduate and Postgraduate:
/// 0-5yrs -> Undergraduate
/// 6-11yrs -> Postgraduate
/// 12+yrs -> Postgraduate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static void Run()
IDataView trainData = mlContext.Data.ReadFromEnumerable(data);

// 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

// Creating a list of keys based on the induced value from the dataset
var temperatureKeys = new List<float>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class SampleInfertDataWithIntArray
/// This example demonstrates the use of the ValueMappingEstimator by mapping string-to-array values which allows for mapping string data
/// to numeric arrays that can then be used as a feature set for a trainer. In this example, we are mapping the education data to
Copy link
Contributor

@rogancarr rogancarr Jan 31, 2019

Choose a reason for hiding this comment

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

As a feature set for a trainer

Does this work? The vectors are of different sizes. #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.

No probably not to pass into a trainer. I went ahead and made them the same size.


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

/// arbitrary integer arrays with the following association:
/// 0-5yrs -> 1,2,3,4
/// 6-11yrs -> 5,6,7
/// 12+yrs -> 42, 32
/// 0-5yrs -> 1, 2, 3
/// 6-11yrs -> 5, 6, 7
/// 12+yrs -> 42,32,64
public static void Run()
{
// Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging,
Expand All @@ -35,7 +35,6 @@ public static void Run()
IDataView trainData = mlContext.Data.ReadFromEnumerable(data);

// 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

// Creating a list of keys based on the Education values from the dataset
var educationKeys = new List<string>()
{
Expand All @@ -47,9 +46,9 @@ public static void Run()
// Sample list of associated array values
var educationValues = new List<int[]>()
{
new int[] { 1,2,3,4 },
new int[] { 1,2,3 },
new int[] { 5,6,7 },
new int[] { 42, 32 }
new int[] { 42,32,64 }
};

// Constructs the ValueMappingEstimator making the ML.net pipeline
Expand All @@ -72,10 +71,10 @@ public static void Run()
//
// Example of mapping string->array
// Age Education EducationFeature
// 26 0 - 5yrs 1,2,3,4
// 42 0 - 5yrs 1,2,3,4
// 39 12 + yrs 42,32
// 34 0 - 5yrs 1,2,3,4
// 26 0 - 5yrs 1,2,3
// 42 0 - 5yrs 1,2,3
// 39 12 + yrs 42,32,64
// 34 0 - 5yrs 1,2,3
// 35 6 - 11yrs 5,6,7
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SampleInfertDataWithFeatures
/// instead of the actual value provides a unique integer representation of the value. When the treatValueAsKeyTypes is true,
/// the ValueMappingEstimator will generate a KeyType for each unique value.
///
/// In this example, the education data is mapped to a grouping of 'Undergraudate' and 'Postgraduate'. Because KeyTypes are used, the
/// In this example, the education data is mapped to a grouping of 'Undergraduate' and 'Postgraduate'. Because KeyTypes are used, the
/// ValueMappingEstimator will output the KeyType value rather than string value of 'Undergraduate' or 'Postgraduate'.
///
/// The KeyToValueEstimator is added to the pipeline to convert the KeyType back to the original value. Therefore the output of this example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static ValueToKeyMappingEstimator MapValueToKey(this TransformsCatalog.Co
=> new ValueToKeyMappingEstimator(CatalogUtils.GetEnvironment(catalog), columns, keyData);

/// <summary>
/// Maps specified keys to specified values
/// <see cref="ValueMappingEstimator"/>
/// </summary>
/// <typeparam name="TInputType">The key type.</typeparam>
/// <typeparam name="TOutputType">The value type.</typeparam>
Expand All @@ -152,7 +152,6 @@ public static ValueToKeyMappingEstimator MapValueToKey(this TransformsCatalog.Co
/// [!code-csharp[ValueMappingEstimator](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/ValueMapping.cs)]
/// ]]></format>
/// </example>

public static ValueMappingEstimator<TInputType, TOutputType> ValueMap<TInputType, TOutputType>(
this TransformsCatalog.ConversionTransforms catalog,
IEnumerable<TInputType> keys,
Expand All @@ -161,10 +160,7 @@ public static ValueMappingEstimator<TInputType, TOutputType> ValueMap<TInputType
=> new ValueMappingEstimator<TInputType, TOutputType>(CatalogUtils.GetEnvironment(catalog), keys, values, columns);

/// <summary>
/// Maps the <paramref name="columns.input"/> using the keys in the dictionary to the values of dictionary i.e.
/// a value 'x' in the <paramref name="columns.input"/> would be mappped to a value stored in dictionary[x].
/// In this case, the <paramref name="lookupMap"/> is used to build up the dictionary where <paramref name="keyColumn"/>
/// and <paramref name="valueColumn"/> specify the keys and values of dictionary respectively.
/// <see cref="ValueMappingEstimator"/>
/// </summary>
/// <param name="catalog">The categorical transform's catalog</param>
/// <param name="lookupMap">An instance of <see cref="IDataView"/> that contains the key and value columns.</param>
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.ML.Data/Transforms/doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@
specific value. The ValueMappingEstimator supports keys and values of different <see cref="System.Type"/> to support different data types.
Examples for using a ValueMappingEstimator are:
<list>
<li>
<item>
<description>Converting a string value to a string value, this can be useful for grouping (i.e. 'cat', 'dog', 'horse' maps to 'mammals')</description>
</li>
<li>
</item>
<item>
<description>Converting a string value to a integer value (i.e. converting the text description like quality to an numeric where 'good' maps to 1, 'poor' maps to 0</description>
</li>
<li>
</item>
<item>
<description>
Converting a integer value to a string value and have the string value represented as a <see cref="KeyType"/>
(i.e. convert zip codes to a state string value, which will generate a unique integer value that can be used as a label.
</description>
</li>
</item>
</list>
Values can be repeated to allow for multiple keys to map to the same value, however keys can not be repeated. The mapping between keys and values
can be specified either through lists, where the key list and value list must be the same size or can be done through an <see cref="IDataView"/>.
Expand Down