TextLoaderSaverCatalog.SaveAsText Metodo
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Salvare come IDataView testo.
public static void SaveAsText (this Microsoft.ML.DataOperationsCatalog catalog, Microsoft.ML.IDataView data, System.IO.Stream stream, char separatorChar = '\t', bool headerRow = true, bool schema = true, bool keepHidden = false, bool forceDense = false);
static member SaveAsText : Microsoft.ML.DataOperationsCatalog * Microsoft.ML.IDataView * System.IO.Stream * char * bool * bool * bool * bool -> unit
<Extension()>
Public Sub SaveAsText (catalog As DataOperationsCatalog, data As IDataView, stream As Stream, Optional separatorChar As Char = '\t', Optional headerRow As Boolean = true, Optional schema As Boolean = true, Optional keepHidden As Boolean = false, Optional forceDense As Boolean = false)
- catalog
- DataOperationsCatalog
Catalogo DataOperationsCatalog .
- data
- IDataView
Visualizzazione dati da salvare.
- stream
- Stream
Flusso in cui scrivere.
- separatorChar
- Char
Separatore di colonna.
- headerRow
- Boolean
Indica se scrivere la riga di intestazione.
- schema
- Boolean
Indica se scrivere il commento dell'intestazione con lo schema.
- keepHidden
- Boolean
Indica se mantenere le colonne nascoste nel set di dati.
- forceDense
- Boolean
Indica se salvare le colonne in formato denso anche se sono vettori di tipo sparse.
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.ML;
namespace Samples.Dynamic
{
public static class SaveAndLoadFromText
{
public static void Example()
{
// Create a new context for ML.NET operations. It can be used for
// exception tracking and logging, as a catalog of available operations
// and as the source of randomness. Setting the seed to a fixed number
// in this example to make outputs deterministic.
var mlContext = new MLContext(seed: 0);
// Create a list of training data points.
var dataPoints = new List<DataPoint>()
{
new DataPoint(){ Label = 0, Features = 4},
new DataPoint(){ Label = 0, Features = 5},
new DataPoint(){ Label = 0, Features = 6},
new DataPoint(){ Label = 1, Features = 8},
new DataPoint(){ Label = 1, Features = 9},
};
// Convert the list of data points to an IDataView object, which is
// consumable by ML.NET API.
IDataView data = mlContext.Data.LoadFromEnumerable(dataPoints);
// Create a FileStream object and write the IDataView to it as a text
// file.
using (FileStream stream = new FileStream("data.tsv", FileMode.Create))
mlContext.Data.SaveAsText(data, stream);
// Create an IDataView object by loading the text file.
IDataView loadedData = mlContext.Data.LoadFromTextFile("data.tsv");
// Inspect the data that is loaded from the previously saved text file.
var loadedDataEnumerable = mlContext.Data
.CreateEnumerable<DataPoint>(loadedData, reuseRowObject: false);
foreach (DataPoint row in loadedDataEnumerable)
Console.WriteLine($"{row.Label}, {row.Features}");
// Preview of the loaded data.
// 0, 4
// 0, 5
// 0, 6
// 1, 8
// 1, 9
}
// Example with label and feature values. A data set is a collection of such
// examples.
private class DataPoint
{
public float Label { get; set; }
public float Features { get; set; }
}
}
}
Prodotto | Versioni |
---|---|
ML.NET | 1.0.0, 1.1.0, 1.2.0, 1.3.1, 1.4.0, 1.5.0, 1.6.0, 1.7.0, 2.0.0, 3.0.0 |