-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Reformatting Conversion, FeatureSelection and Image Analytics of Transform to Width 85 #3943
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9267d02
samples/dynamic/transforms/conversions formatted to 85 char
f2a18ed
samples/dynamic/transforms/featureselection formatted to 85 char
38c8938
ImageAnalytics
67080d1
ImageAnalytics
ecd2738
small corrections to formatting
91532b0
Merge branch 'transform85' of https://github.com/RadicalRayan/machine…
3deb533
minor tab and empty line changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ public class KeyToValueToKey | |
{ | ||
public static void Example() | ||
{ | ||
// Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, | ||
// as well as the source of randomness. | ||
// Create a new ML context, for ML.NET operations. It can be used for | ||
// exception tracking and logging, as well as the source of randomness. | ||
var mlContext = new MLContext(); | ||
|
||
// Get a small dataset as an IEnumerable. | ||
|
@@ -27,25 +27,40 @@ public static void Example() | |
|
||
// A pipeline to convert the terms of the 'Review' column in | ||
// making use of default settings. | ||
var defaultPipeline = mlContext.Transforms.Text.TokenizeIntoWords("TokenizedText", nameof(DataPoint.Review)) | ||
.Append(mlContext.Transforms.Conversion.MapValueToKey(nameof(TransformedData.Keys), "TokenizedText")); | ||
var defaultPipeline = mlContext.Transforms.Text.TokenizeIntoWords( | ||
"TokenizedText", nameof(DataPoint.Review)).Append(mlContext | ||
.Transforms.Conversion.MapValueToKey(nameof(TransformedData.Keys), | ||
"TokenizedText")); | ||
|
||
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. please move .Append to a new line. |
||
// Another pipeline, that customizes the advanced settings of the ValueToKeyMappingEstimator. | ||
// We can change the maximumNumberOfKeys to limit how many keys will get generated out of the set of words, | ||
// and condition the order in which they get evaluated by changing keyOrdinality from the default ByOccurence (order in which they get encountered) | ||
// to value/alphabetically. | ||
var customizedPipeline = mlContext.Transforms.Text.TokenizeIntoWords("TokenizedText", nameof(DataPoint.Review)) | ||
.Append(mlContext.Transforms.Conversion.MapValueToKey(nameof(TransformedData.Keys), "TokenizedText", maximumNumberOfKeys: 10, | ||
keyOrdinality: ValueToKeyMappingEstimator.KeyOrdinality.ByValue)); | ||
// Another pipeline, that customizes the advanced settings of the | ||
// ValueToKeyMappingEstimator. We can change the maximumNumberOfKeys to | ||
// limit how many keys will get generated out of the set of words, and | ||
// condition the order in which they get evaluated by changing | ||
// keyOrdinality from the default ByOccurence (order in which they get | ||
// encountered) to value/alphabetically. | ||
var customizedPipeline = mlContext.Transforms.Text.TokenizeIntoWords( | ||
"TokenizedText", nameof(DataPoint.Review)).Append(mlContext | ||
.Transforms.Conversion.MapValueToKey(nameof(TransformedData.Keys), | ||
"TokenizedText", maximumNumberOfKeys: 10, keyOrdinality: | ||
ValueToKeyMappingEstimator.KeyOrdinality.ByValue)); | ||
|
||
// The transformed data. | ||
var transformedDataDefault = defaultPipeline.Fit(trainData).Transform(trainData); | ||
var transformedDataCustomized = customizedPipeline.Fit(trainData).Transform(trainData); | ||
var transformedDataDefault = defaultPipeline.Fit(trainData).Transform( | ||
trainData); | ||
|
||
var transformedDataCustomized = customizedPipeline.Fit(trainData) | ||
.Transform(trainData); | ||
|
||
// Getting the resulting data as an IEnumerable. | ||
// This will contain the newly created columns. | ||
IEnumerable<TransformedData> defaultData = mlContext.Data.CreateEnumerable<TransformedData>(transformedDataDefault, reuseRowObject: false); | ||
IEnumerable<TransformedData> customizedData = mlContext.Data.CreateEnumerable<TransformedData>(transformedDataCustomized, reuseRowObject: false); | ||
IEnumerable<TransformedData> defaultData = mlContext.Data. | ||
CreateEnumerable<TransformedData>(transformedDataDefault, | ||
reuseRowObject: false); | ||
|
||
IEnumerable<TransformedData> customizedData = mlContext.Data. | ||
CreateEnumerable<TransformedData>(transformedDataCustomized, | ||
reuseRowObject: false); | ||
|
||
Console.WriteLine($"Keys"); | ||
foreach (var dataRow in defaultData) | ||
Console.WriteLine($"{string.Join(',', dataRow.Keys)}"); | ||
|
@@ -65,13 +80,17 @@ public static void Example() | |
// 8,2,9,7,6,4 | ||
// 3,10,0,0,0 | ||
// 3,10,0,0,0,8 | ||
// Retrieve the original values, by appending the KeyToValue etimator to the existing pipelines | ||
// to convert the keys back to the strings. | ||
var pipeline = defaultPipeline.Append(mlContext.Transforms.Conversion.MapKeyToValue(nameof(TransformedData.Keys))); | ||
// Retrieve the original values, by appending the KeyToValue etimator to | ||
// the existing pipelines to convert the keys back to the strings. | ||
var pipeline = defaultPipeline.Append(mlContext.Transforms.Conversion | ||
.MapKeyToValue(nameof(TransformedData.Keys))); | ||
|
||
transformedDataDefault = pipeline.Fit(trainData).Transform(trainData); | ||
|
||
// Preview of the DefaultColumnName column obtained. | ||
var originalColumnBack = transformedDataDefault.GetColumn<VBuffer<ReadOnlyMemory<char>>>(transformedDataDefault.Schema[nameof(TransformedData.Keys)]); | ||
var originalColumnBack = transformedDataDefault.GetColumn<VBuffer< | ||
ReadOnlyMemory<char>>>(transformedDataDefault.Schema[nameof( | ||
TransformedData.Keys)]); | ||
|
||
foreach (var row in originalColumnBack) | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
new line between any two lines that were broken down into multiple lines but no new line between multiple breakdowns of a single line.