Skip to content

Saving a DataView to a file should be simpler and not through to the LocalEnvironment class #1553

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
CESARDELATORRE opened this issue Nov 6, 2018 · 1 comment
Labels
API Issues pertaining the friendly API usability Smoothing user interaction or experience

Comments

@CESARDELATORRE
Copy link
Contributor

I'm using v0.7.
Issue: Saving a DataView to a file should be simpler and not having to directly use the LocalEnvironment class.
If there's any new way to do this in v0.7 or v08, please tell me, but I haven't found it. :)

As far as I know, this is the code needed, currently:

                // save test split dataset
                IHostEnvironment env = (IHostEnvironment)mlContext;
                using (var ch = env.Start("SaveData"))
                using (var file = env.CreateOutputFile(Path.Combine(_outputPath, "testData.idv")))
                {
                    var saver = new BinarySaver(mlContext, new BinarySaver.Arguments());
                    DataSaverUtils.SaveDataView(ch, saver, testDataView, file);
                }

First, it needs to use the IChannel object that has to be obtained from the IHostEnvironment object that you can get by casting the MLContext object to IHostEnvironment. The developer shouldn't need to use IHostEnvironment in any case, I think.

Then, still a few more lines for saving the file.

We should aim to achieve a simpler API for doing this, just something like:

testDataView.SaveToFile(testDataSetFilePath);

Or if we need to do it through any utility class:

DataSaverUtils.SaveDataViewToFile(testDataView, testDataSetFilePath);

@CESARDELATORRE CESARDELATORRE added API Issues pertaining the friendly API usability Smoothing user interaction or experience labels Nov 6, 2018
@TomFinley
Copy link
Contributor

TomFinley commented Nov 7, 2018

MLContext.Data.SaveAsText -- generally the common idiom in 0.7 and going forward we think will be that this will be the central structure to "find" commonly used operations. Please refer to #1098 to familiarize yourself with the idiom.

Sort of a factory of everything. That's not an antipattern, is it? 😉

@ghost ghost locked as resolved and limited conversation to collaborators Mar 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Issues pertaining the friendly API usability Smoothing user interaction or experience
Projects
None yet
Development

No branches or pull requests

3 participants