Skip to content

Sample for ReplaceMissingValues. #2773

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

Closed
wants to merge 3 commits into from
Closed
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
Next Next commit
Sample for ReplaceMissingValues.
  • Loading branch information
codemzs committed Feb 27, 2019
commit c95dc9c0652a7e808b5061109dbb2e5304e89ea3
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.ML.Data;
using Microsoft.ML.SamplesUtils;

namespace Microsoft.ML.Samples.Dynamic
{
public static class ReplaceMissingValues
{
public static void Example()
{
// Creating the ML.Net IHostEnvironment object, needed for the pipeline.
Copy link
Contributor

@zeahmed zeahmed Feb 27, 2019

Choose a reason for hiding this comment

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

// Creating the ML.Net IHostEnvironment object, needed for the pipeline. [](start = 12, length = 72)

Following is the standard comments for the MLContext in the samples.
// 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.

Please see other samples in the folder.
#Resolved

var mlContext = new MLContext();

// Download the training and validation files.
string dataFile = DatasetUtils.DownloadMslrWeb10k();
Copy link
Contributor

@zeahmed zeahmed Feb 27, 2019

Choose a reason for hiding this comment

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

DownloadMslrWeb10k [](start = 43, length = 18)

You can use the LoadFeaturizedMslrWeb10kDataset instead which will save you creating the data processing step. This is the standard in the samples. #Resolved

Copy link
Member

@wschin wschin Feb 28, 2019

Choose a reason for hiding this comment

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

My feeling is that we should use in-memory data when possible. In, #2726, we discuss some of in-memory data's advantages. #Resolved


// Create the loader to load the data.
var loader = mlContext.Data.CreateTextLoader(
columns: new[]
{
new TextLoader.Column("Label", DataKind.Single, 0),
new TextLoader.Column("GroupId", DataKind.String, 1),
new TextLoader.Column("Features", DataKind.Single, new[] { new TextLoader.Range(2, 138) })
}
);

// Load the raw dataset.
var data = loader.Load(dataFile);
Copy link
Member

Choose a reason for hiding this comment

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

data [](start = 16, length = 4)

show a preview of before the transformation too.


// Create the featurization pipeline. First, hash the GroupId column.
var pipeline = mlContext.Transforms.Conversion.Hash("GroupId")
// Replace missing values in Features column with the default replacement value for its type.
.Append(mlContext.Transforms.ReplaceMissingValues("Features"));

// Fit the pipeline and transform the dataset.
var transformedData = pipeline.Fit(data).Transform(data);
Copy link
Contributor

Choose a reason for hiding this comment

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

transformedData [](start = 16, length = 15)

Can you show some output after this line? e.g. the data preview or any metrics etc.

Copy link
Member

Choose a reason for hiding this comment

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

+1. Please also show how to inspect the prediction result example-by-example.

}
}
}