Skip to content

Clean SamplesUtils - #3594

Merged
wschin merged 3 commits into
dotnet:masterfrom
wschin:clean-samplesutils
May 24, 2019
Merged

Clean SamplesUtils#3594
wschin merged 3 commits into
dotnet:masterfrom
wschin:clean-samplesutils

Conversation

@wschin

@wschin wschin commented Apr 25, 2019

Copy link
Copy Markdown
Contributor

This PR cleans SampleUtils a bit. Toward #3584.

  • If a function/class is used only in less than two places, we copy them wherever it's used.
  • Function/class referenced by nothing is removed.

Currently, we can't not remove SamplesUtils entirely because some samples are still using it.

@wschin wschin self-assigned this Apr 25, 2019
Console.WriteLine($"Mean Squared Error: {metrics.MeanSquaredError:F2}");
Console.WriteLine($"Root Mean Squared Error: {metrics.RootMeanSquaredError:F2}");
Console.WriteLine($"RSquared: {metrics.RSquared:F2}");
}

@shmoradims shmoradims Apr 25, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

for trainers, we should modify the .ttinclude template file, not the cs file directly. #Resolved

@wschin wschin Apr 25, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

*Advanced.cs are not API samples. They are legacy end-to-end pipelines saved for future use. #Resolved

data.Add(new SampleSentimentData { Sentiment = true, SentimentText = "Best game I've ever played." });
data.Add(new SampleSentimentData { Sentiment = false, SentimentText = "==RUDE== Dude, 2" });
data.Add(new SampleSentimentData { Sentiment = true, SentimentText = "Until the next game, this is the best Xbox game!" });
return data;

@shmoradims shmoradims Apr 25, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

let's use initializer, instead of Add one-by-one, remove the function-call, and just move the list up in the Example().

var data = new List{
datapoint1,
datapoint2,
....
} #Resolved

data.Add(new SampleVectorOfNumbersData
{
Features = new float[10] { 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 }
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ditto.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

similar change. please create the data inline with initializers, similar to NgramExtraction.


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


// Get a small dataset as an IEnumerable and convert to IDataView.
var data = Microsoft.ML.SamplesUtils.DatasetUtils.GetSentimentData();
var data = GetSentimentData();

@najeeb-kazmi najeeb-kazmi Apr 26, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

var [](start = 12, length = 3)

You have IEnumerable<SampleSentimentData> in the NGram sample. Let's adopt a consistent scheme, either var everywhere or the concrete type everywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do var.


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

@najeeb-kazmi

najeeb-kazmi commented Apr 26, 2019

Copy link
Copy Markdown
Member
    private static (int lines, double columnAverage, double elapsedSeconds) TimeToScanIDataView(MLContext mlContext, IDataView data)

I thought we had decided to not use tuples, at least in the API. Is it okay for samples? @shmoradims


Refers to: docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs:42 in 70a3a18. [](commit_id = 70a3a18, deletion_comment = False)

@najeeb-kazmi najeeb-kazmi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

@wschin

wschin commented Apr 26, 2019

Copy link
Copy Markdown
Contributor Author
    private static (int lines, double columnAverage, double elapsedSeconds) TimeToScanIDataView(MLContext mlContext, IDataView data)

I think they are fine. It's a part of C# language and this is a C# sample. I remember one reason not to use tuple is that F# doesn't support it well.


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


Refers to: docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs:42 in 70a3a18. [](commit_id = 70a3a18, deletion_comment = False)

@codecov

codecov Bot commented Apr 26, 2019

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@51b10fc). Click here to learn what that means.
The diff coverage is 97.5%.

@@            Coverage Diff            @@
##             master    #3594   +/-   ##
=========================================
  Coverage          ?    72.9%           
=========================================
  Files             ?      807           
  Lines             ?   145214           
  Branches          ?    16237           
=========================================
  Hits              ?   105867           
  Misses            ?    34924           
  Partials          ?     4423
Flag Coverage Δ
#Debug 72.9% <97.5%> (?)
#production 68.43% <0%> (?)
#test 89.05% <100%> (?)
Impacted Files Coverage Δ
...c/Microsoft.ML.SamplesUtils/SamplesDatasetUtils.cs 39.88% <0%> (ø)
...rosoft.ML.Tests/TrainerEstimators/FAFMEstimator.cs 100% <100%> (ø)

@shmoradims

Copy link
Copy Markdown
    private static (int lines, double columnAverage, double elapsedSeconds) TimeToScanIDataView(MLContext mlContext, IDataView data)

it's ok here. but since it's just a util, it would be cleaner to make the function void, and print the values in the function instead of returning the stats and printing in the main example. The user can still see the produced output, from the proceeding comments. So this is just simpler and we don't have to worry if users know about tuples or not.


In reply to: 487105281 [](ancestors = 487105281,486880743)


Refers to: docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs:42 in 70a3a18. [](commit_id = 70a3a18, deletion_comment = False)

@shmoradims shmoradims left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

:shipit:

@wschin
wschin force-pushed the clean-samplesutils branch from 55b723d to 936c406 Compare May 17, 2019 17:01
@wschin
wschin merged commit 4073653 into dotnet:master May 24, 2019
@wschin
wschin deleted the clean-samplesutils branch May 24, 2019 20:20
@ghost ghost locked as resolved and limited conversation to collaborators Mar 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants