@@ -115,7 +115,9 @@ If the schema of the data is not known at compile time, or too cumbersome, you c
115115var mlContext = new MLContext ();
116116
117117// Create the reader: define the data columns and where to find them in the text file.
118- var reader = mlContext .Data .TextReader (new [] {
118+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
119+ {
120+ Column = new [] {
119121 // A boolean column depicting the 'label'.
120122 new TextLoader .Column (" IsOver50K" , DataKind .BL , 0 ),
121123 // Three text columns.
@@ -124,8 +126,8 @@ var reader = mlContext.Data.TextReader(new[] {
124126 new TextLoader .Column (" MaritalStatus" , DataKind .TX , 3 )
125127 },
126128 // First line of the file is a header, not a data row.
127- hasHeader : true
128- );
129+ HasHeader = true
130+ } );
129131
130132// Now read the file (remember though, readers are lazy, so the actual reading will happen when the data is accessed).
131133var data = reader .Read (dataPath );
@@ -173,17 +175,19 @@ The code is very similar using the dynamic API:
173175var mlContext = new MLContext ();
174176
175177// Create the reader: define the data columns and where to find them in the text file.
176- var reader = mlContext .Data .TextReader (new [] {
178+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
179+ {
180+ Column = new [] {
177181 // A boolean column depicting the 'label'.
178- new TextLoader .Column (" IsOver50K " , DataKind .BL , 0 ),
182+ new TextLoader .Column (" IsOver50k " , DataKind .BL , 0 ),
179183 // Three text columns.
180184 new TextLoader .Column (" Workclass" , DataKind .TX , 1 ),
181185 new TextLoader .Column (" Education" , DataKind .TX , 2 ),
182186 new TextLoader .Column (" MaritalStatus" , DataKind .TX , 3 )
183187 },
184188 // First line of the file is a header, not a data row.
185- hasHeader : true
186- );
189+ HasHeader = true
190+ } );
187191
188192var data = reader .Read (exampleFile1 , exampleFile2 );
189193```
@@ -361,17 +365,19 @@ You can also use the dynamic API to create the equivalent of the previous pipeli
361365var mlContext = new MLContext ();
362366
363367// Create the reader: define the data columns and where to find them in the text file.
364- var reader = mlContext .Data .TextReader (new [] {
368+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
369+ {
370+ Column = new [] {
365371 // A boolean column depicting the 'label'.
366- new TextLoader .Column (" IsOver50K " , DataKind .BL , 0 ),
372+ new TextLoader .Column (" IsOver50k " , DataKind .BL , 0 ),
367373 // Three text columns.
368374 new TextLoader .Column (" Workclass" , DataKind .TX , 1 ),
369375 new TextLoader .Column (" Education" , DataKind .TX , 2 ),
370376 new TextLoader .Column (" MaritalStatus" , DataKind .TX , 3 )
371377 },
372378 // First line of the file is a header, not a data row.
373- hasHeader : true
374- );
379+ HasHeader = true
380+ } );
375381
376382// Start creating our processing pipeline. For now, let's just concatenate all the text columns
377383// together into one.
@@ -462,18 +468,20 @@ var mlContext = new MLContext();
462468
463469// Step one: read the data as an IDataView.
464470// First, we define the reader: specify the data columns and where to find them in the text file.
465- var reader = mlContext .Data .TextReader (new [] {
471+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
472+ {
473+ Column = new [] {
466474 // We read the first 11 values as a single float vector.
467475 new TextLoader .Column (" FeatureVector" , DataKind .R4 , 0 , 10 ),
468476
469477 // Separately, read the target variable.
470478 new TextLoader .Column (" Target" , DataKind .R4 , 11 ),
471479 },
472480 // First line of the file is a header, not a data row.
473- hasHeader : true ,
481+ HasHeader = true ,
474482 // Default separator is tab, but we need a semicolon.
475- separatorChar : ';'
476- );
483+ Separator = " ; "
484+ } );
477485
478486// Now read the file (remember though, readers are lazy, so the actual reading will happen when the data is accessed).
479487var trainData = reader .Read (trainDataPath );
@@ -609,7 +617,9 @@ var mlContext = new MLContext();
609617
610618// Step one: read the data as an IDataView.
611619// First, we define the reader: specify the data columns and where to find them in the text file.
612- var reader = mlContext .Data .TextReader (new [] {
620+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
621+ {
622+ Column = new [] {
613623 new TextLoader .Column (" SepalLength" , DataKind .R4 , 0 ),
614624 new TextLoader .Column (" SepalWidth" , DataKind .R4 , 1 ),
615625 new TextLoader .Column (" PetalLength" , DataKind .R4 , 2 ),
@@ -618,8 +628,8 @@ var reader = mlContext.Data.TextReader(new[] {
618628 new TextLoader .Column (" Label" , DataKind .TX , 4 ),
619629 },
620630 // Default separator is tab, but the dataset has comma.
621- separatorChar : ','
622- );
631+ Separator = " , "
632+ } );
623633
624634// Retrieve the training data.
625635var trainData = reader .Read (irisDataPath );
@@ -900,15 +910,17 @@ You can achieve the same results using the dynamic API.
900910var mlContext = new MLContext ();
901911
902912// Define the reader: specify the data columns and where to find them in the text file.
903- var reader = mlContext .Data .TextReader (new [] {
913+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
914+ {
915+ Column = new [] {
904916 // The four features of the Iris dataset will be grouped together as one Features column.
905917 new TextLoader .Column (" Features" , DataKind .R4 , 0 , 3 ),
906918 // Label: kind of iris.
907919 new TextLoader .Column (" Label" , DataKind .TX , 4 ),
908920 },
909921 // Default separator is tab, but the dataset has comma.
910- separatorChar : ','
911- );
922+ Separator = " , "
923+ } );
912924
913925// Read the training data.
914926var trainData = reader .Read (dataPath );
@@ -1015,8 +1027,9 @@ You can achieve the same results using the dynamic API.
10151027var mlContext = new MLContext ();
10161028
10171029// Define the reader: specify the data columns and where to find them in the text file.
1018- var reader = mlContext .Data .TextReader (new []
1019- {
1030+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1031+ {
1032+ Column = new [] {
10201033 new TextLoader .Column (" Label" , DataKind .BL , 0 ),
10211034 // We will load all the categorical features into one vector column of size 8.
10221035 new TextLoader .Column (" CategoricalFeatures" , DataKind .TX , 1 , 8 ),
@@ -1025,8 +1038,8 @@ var reader = mlContext.Data.TextReader(new[]
10251038 // Let's also separately load the 'Workclass' column.
10261039 new TextLoader .Column (" Workclass" , DataKind .TX , 1 ),
10271040 },
1028- hasHeader : true
1029- );
1041+ HasHeader = true
1042+ } );
10301043
10311044// Read the data.
10321045var data = reader .Read (dataPath );
@@ -1141,13 +1154,14 @@ You can achieve the same results using the dynamic API.
11411154var mlContext = new MLContext ();
11421155
11431156// Define the reader: specify the data columns and where to find them in the text file.
1144- var reader = mlContext .Data .TextReader (new []
1145- {
1157+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1158+ {
1159+ Column = new [] {
11461160 new TextLoader .Column (" IsToxic" , DataKind .BL , 0 ),
11471161 new TextLoader .Column (" Message" , DataKind .TX , 1 ),
11481162 },
1149- hasHeader : true
1150- );
1163+ HasHeader = true
1164+ } );
11511165
11521166// Read the data.
11531167var data = reader .Read (dataPath );
@@ -1260,8 +1274,9 @@ var mlContext = new MLContext();
12601274
12611275// Step one: read the data as an IDataView.
12621276// First, we define the reader: specify the data columns and where to find them in the text file.
1263- var reader = mlContext .Data .TextReader (new []
1264- {
1277+ var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1278+ {
1279+ Column = new [] {
12651280 // We read the first 11 values as a single float vector.
12661281 new TextLoader .Column (" SepalLength" , DataKind .R4 , 0 ),
12671282 new TextLoader .Column (" SepalWidth" , DataKind .R4 , 1 ),
@@ -1271,8 +1286,8 @@ var reader = mlContext.Data.TextReader(new[]
12711286 new TextLoader .Column (" Label" , DataKind .TX , 4 ),
12721287 },
12731288 // Default separator is tab, but the dataset has comma.
1274- separatorChar : ','
1275- );
1289+ Separator = " , "
1290+ } );
12761291
12771292// Read the data.
12781293var data = reader .Read (dataPath );
0 commit comments