TextLoaderSaverCatalog.LoadFromTextFile 方法

定義

多載

LoadFromTextFile(DataOperationsCatalog, String, TextLoader+Options)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

LoadFromTextFile(DataOperationsCatalog, String, TextLoader+Column[], Char, Boolean, Boolean, Boolean, Boolean)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

LoadFromTextFile<TInput>(DataOperationsCatalog, String, TextLoader+Options)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

LoadFromTextFile<TInput>(DataOperationsCatalog, String, Char, Boolean, Boolean, Boolean, Boolean)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

LoadFromTextFile(DataOperationsCatalog, String, TextLoader+Options)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

public static Microsoft.ML.IDataView LoadFromTextFile (this Microsoft.ML.DataOperationsCatalog catalog, string path, Microsoft.ML.Data.TextLoader.Options options = default);
static member LoadFromTextFile : Microsoft.ML.DataOperationsCatalog * string * Microsoft.ML.Data.TextLoader.Options -> Microsoft.ML.IDataView
<Extension()>
Public Function LoadFromTextFile (catalog As DataOperationsCatalog, path As String, Optional options As TextLoader.Options = Nothing) As IDataView

參數

path
String

指定要從中載入之檔案的檔案或路徑。

options
TextLoader.Options

定義載入作業的設定。

傳回

範例

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; }
        }
    }
}

適用於

LoadFromTextFile(DataOperationsCatalog, String, TextLoader+Column[], Char, Boolean, Boolean, Boolean, Boolean)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

public static Microsoft.ML.IDataView LoadFromTextFile (this Microsoft.ML.DataOperationsCatalog catalog, string path, Microsoft.ML.Data.TextLoader.Column[] columns, char separatorChar = '\t', bool hasHeader = false, bool allowQuoting = false, bool trimWhitespace = false, bool allowSparse = false);
static member LoadFromTextFile : Microsoft.ML.DataOperationsCatalog * string * Microsoft.ML.Data.TextLoader.Column[] * char * bool * bool * bool * bool -> Microsoft.ML.IDataView
<Extension()>
Public Function LoadFromTextFile (catalog As DataOperationsCatalog, path As String, columns As TextLoader.Column(), Optional separatorChar As Char = '\t', Optional hasHeader As Boolean = false, Optional allowQuoting As Boolean = false, Optional trimWhitespace As Boolean = false, Optional allowSparse As Boolean = false) As IDataView

參數

path
String

檔案的路徑 (s) 。

columns
TextLoader.Column[]

架構的資料行。

separatorChar
Char

用來作為資料列中資料點之間分隔符號的字元。 根據預設,索引標籤字元會當做分隔符號使用。

hasHeader
Boolean

檔案是否有標頭。 當 為 時 true ,載入器會在呼叫 時 Load(IMultiStreamSource) 略過第一行。

allowQuoting
Boolean

輸入是否可能包含雙引號值。 此參數用來區分輸入值中的分隔符號與實際分隔符號。 當 為 時 true ,雙引號內的分隔符號會視為輸入值的一部分。 當 為 時 false ,所有分隔符號,甚至是那些引號,都會被視為分隔新資料行。 它也可用來區分空白值與遺漏值。 當 時 true ,遺漏值會以連續分隔符號表示,並以 「」 表示空白值。 當 為 時 false ,空值會以連續分隔符號表示,而遺漏值則以 中記載 DataKind 的每個類型的預設遺漏值表示。

trimWhitespace
Boolean

從行中移除尾端空白字元。

allowSparse
Boolean

輸入是否可能包含疏鬆標記法。 例如,包含 「5 2:6 4:3」 的資料清單示有 5 個數據行,而唯一的非零資料行是 2 和 4,分別具有 6 和 3 的值。 資料行索引是以零起始,因此資料行 2 和 4 代表第三欄和第 5 個數據行。 資料行可能也有密集值,後面接著以這種方式表示的疏鬆值。 例如,包含 「1 2 5 2:6 4:3」 的資料列代表兩個具有值 1 和 2 的密集資料行,後面接著 5 個疏鬆表示值為 0、0、6、0 和 3 的資料行。 疏鬆資料行的索引從 0 開始,即使 0 代表第三個數據行也一樣。

傳回

資料檢視。

適用於

LoadFromTextFile<TInput>(DataOperationsCatalog, String, TextLoader+Options)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

public static Microsoft.ML.IDataView LoadFromTextFile<TInput> (this Microsoft.ML.DataOperationsCatalog catalog, string path, Microsoft.ML.Data.TextLoader.Options options);
static member LoadFromTextFile : Microsoft.ML.DataOperationsCatalog * string * Microsoft.ML.Data.TextLoader.Options -> Microsoft.ML.IDataView
<Extension()>
Public Function LoadFromTextFile(Of TInput) (catalog As DataOperationsCatalog, path As String, options As TextLoader.Options) As IDataView

類型參數

TInput

參數

path
String

指定要從中載入之檔案的檔案或路徑。

options
TextLoader.Options

定義載入作業的設定。 不需要指定 Columns 欄位,因為此方法會推斷資料行。

傳回

資料檢視。

適用於

LoadFromTextFile<TInput>(DataOperationsCatalog, String, Char, Boolean, Boolean, Boolean, Boolean)

IDataView使用 TextLoader 從文字檔載入 。 請注意, IDataView 's 是延遲的,因此此處不會發生任何實際的載入,只是架構驗證。

public static Microsoft.ML.IDataView LoadFromTextFile<TInput> (this Microsoft.ML.DataOperationsCatalog catalog, string path, char separatorChar = '\t', bool hasHeader = false, bool allowQuoting = false, bool trimWhitespace = false, bool allowSparse = false);
static member LoadFromTextFile : Microsoft.ML.DataOperationsCatalog * string * char * bool * bool * bool * bool -> Microsoft.ML.IDataView
<Extension()>
Public Function LoadFromTextFile(Of TInput) (catalog As DataOperationsCatalog, path As String, Optional separatorChar As Char = '\t', Optional hasHeader As Boolean = false, Optional allowQuoting As Boolean = false, Optional trimWhitespace As Boolean = false, Optional allowSparse As Boolean = false) As IDataView

類型參數

TInput

參數

path
String

檔案的路徑 (s) 。

separatorChar
Char

資料行分隔符號。 預設值為 '\t'

hasHeader
Boolean

檔案是否有標頭。 當 為 時 true ,載入器會在呼叫 時 Load(IMultiStreamSource) 略過第一行。

allowQuoting
Boolean

輸入是否可能包含雙引號值。 此參數用來區分輸入值中的分隔符號與實際分隔符號。 當 為 時 true ,雙引號內的分隔符號會視為輸入值的一部分。 當 為 時 false ,所有分隔符號,甚至是那些引號,都會被視為分隔新資料行。 它也可用來區分空白值與遺漏值。 當 時 true ,遺漏值會以連續分隔符號表示,並以 「」 表示空白值。 當 為 時 false ,空值會以連續分隔符號表示,而遺漏值則以 中記載 DataKind 的每個類型的預設遺漏值表示。

trimWhitespace
Boolean

從行中移除尾端空白字元。

allowSparse
Boolean

輸入是否可能包含疏鬆標記法。 例如,包含 「5 2:6 4:3」 的資料清單示有 5 個數據行,而唯一的非零資料行是 2 和 4,分別具有 6 和 3 的值。 資料行索引是以零起始,因此資料行 2 和 4 代表第三欄和第 5 個數據行。 資料行可能也有密集值,後面接著以這種方式表示的疏鬆值。 例如,包含 「1 2 5 2:6 4:3」 的資料列代表兩個具有值 1 和 2 的密集資料行,後面接著 5 個疏鬆表示值為 0、0、6、0 和 3 的資料行。 疏鬆資料行的索引從 0 開始,即使 0 代表第三個數據行也一樣。

傳回

資料檢視。

適用於