Skip to content

Update cookbook to latest API #4706

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 6 commits into from
Feb 5, 2020
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
Align naming in cookbook samples tests with changes
  • Loading branch information
najeeb-kazmi committed Jan 27, 2020
commit b13fc53072df20b633f8247af6b909be1ed2837c
2 changes: 1 addition & 1 deletion docs/code/MlNetCookBook.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ var workclasses = transformedData.GetColumn<float[]>(transformedData.Schema["Wor
// Here's how we could do this:

var fullLearningPipeline = pipeline
// Concatenate two of the 3 categorical columns, and the numeric features.
// Concatenate two of the 3 categorical pipelines, and the numeric features.
.Append(mlContext.Transforms.Concatenate("Features", "NumericalFeatures", "CategoricalBag", "WorkclassOneHotTrimmed"))
// Cache data in memory so that the following trainer will be able to access training examples without
// loading them from disk multiple times.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void TrainRegression(string trainDataPath, string testDataPath, string m

// Step one: read the data as an IDataView.
// Read the file (remember though, loaders are lazy, so the actual reading will happen when the data is accessed).
var trainData = mlContext.Data.LoadFromTextFile<AdultData>(trainDataPath,
var trainData = mlContext.Data.LoadFromTextFile<RegressionData>(trainDataPath,
// Default separator is tab, but we need a semicolon.
separatorChar: ';'
,
Expand Down Expand Up @@ -111,7 +111,7 @@ private void TrainRegression(string trainDataPath, string testDataPath, string m
var model = pipeline.Fit(trainData);

// Read the test dataset.
var testData = mlContext.Data.LoadFromTextFile<AdultData>(testDataPath,
var testData = mlContext.Data.LoadFromTextFile<RegressionData>(testDataPath,
// Default separator is tab, but we need a semicolon.
separatorChar: ';'
,
Expand Down Expand Up @@ -451,15 +451,15 @@ private void TextFeaturizationOn(string dataPath)
.Append(mlContext.Transforms.Text.NormalizeText("NormalizedMessage", "Message"))

// NLP pipeline 1: bag of words.
.Append(new WordBagEstimator(mlContext, "BagOfWords", "NormalizedMessage"))
.Append(mlContext.Transforms.Text.ProduceWordBags("BagOfWords", "NormalizedMessage"))

// NLP pipeline 2: bag of bigrams, using hashes instead of dictionary indices.
.Append(new WordHashBagEstimator(mlContext, "BagOfBigrams","NormalizedMessage",
.Append(mlContext.Transforms.Text.ProduceHashedWordBags("BagOfBigrams","NormalizedMessage",
ngramLength: 2, useAllLengths: false))

// NLP pipeline 3: bag of tri-character sequences with TF-IDF weighting.
.Append(mlContext.Transforms.Text.TokenizeIntoCharactersAsKeys("MessageChars", "Message"))
.Append(new NgramExtractingEstimator(mlContext, "BagOfTrichar", "MessageChars",
.Append(mlContext.Transforms.Text.ProduceNgrams("BagOfTrichar", "MessageChars",
ngramLength: 3, weighting: NgramExtractingEstimator.WeightingCriteria.TfIdf))

// NLP pipeline 4: word embeddings.
Expand Down Expand Up @@ -609,7 +609,7 @@ private void ReadDataDynamic(string dataPath)
var mlContext = new MLContext();

// Now read the file (remember though, loaders are lazy, so the actual reading will happen when the data is accessed).
var loader = mlContext.Data.LoadFromTextFile<AdultData>(dataPath,
var loader = mlContext.Data.LoadFromTextFile<RegressionData>(dataPath,
// Default separator is tab, but we need a comma.
separatorChar: ',');
}
Expand Down Expand Up @@ -776,7 +776,7 @@ private class IrisInputAllFeatures
public float Features { get; set; }
}

private class AdultData
private class RegressionData
{
[LoadColumn(0, 10), ColumnName("FeatureVector")]
public float Features { get; set; }
Expand Down