@@ -115,9 +115,7 @@ If the schema of the data is not known at compile time, or too cumbersome, you c
115
115
var mlContext = new MLContext ();
116
116
117
117
// Create the reader: define the data columns and where to find them in the text file.
118
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
119
- {
120
- Column = new [] {
118
+ var reader = mlContext .Data .TextReader (new [] {
121
119
// A boolean column depicting the 'label'.
122
120
new TextLoader .Column (" IsOver50K" , DataKind .BL , 0 ),
123
121
// Three text columns.
@@ -126,8 +124,8 @@ var reader = mlContext.Data.TextReader(new TextLoader.Arguments
126
124
new TextLoader .Column (" MaritalStatus" , DataKind .TX , 3 )
127
125
},
128
126
// First line of the file is a header, not a data row.
129
- HasHeader = true
130
- } );
127
+ hasHeader : true
128
+ );
131
129
132
130
// Now read the file (remember though, readers are lazy, so the actual reading will happen when the data is accessed).
133
131
var data = reader .Read (dataPath );
@@ -175,19 +173,17 @@ The code is very similar using the dynamic API:
175
173
var mlContext = new MLContext ();
176
174
177
175
// Create the reader: define the data columns and where to find them in the text file.
178
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
179
- {
180
- Column = new [] {
176
+ var reader = mlContext .Data .TextReader (new [] {
181
177
// A boolean column depicting the 'label'.
182
- new TextLoader .Column (" IsOver50k " , DataKind .BL , 0 ),
178
+ new TextLoader .Column (" IsOver50K " , DataKind .BL , 0 ),
183
179
// Three text columns.
184
180
new TextLoader .Column (" Workclass" , DataKind .TX , 1 ),
185
181
new TextLoader .Column (" Education" , DataKind .TX , 2 ),
186
182
new TextLoader .Column (" MaritalStatus" , DataKind .TX , 3 )
187
183
},
188
184
// First line of the file is a header, not a data row.
189
- HasHeader = true
190
- } );
185
+ hasHeader : true
186
+ );
191
187
192
188
var data = reader .Read (exampleFile1 , exampleFile2 );
193
189
```
@@ -365,19 +361,17 @@ You can also use the dynamic API to create the equivalent of the previous pipeli
365
361
var mlContext = new MLContext ();
366
362
367
363
// Create the reader: define the data columns and where to find them in the text file.
368
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
369
- {
370
- Column = new [] {
364
+ var reader = mlContext .Data .TextReader (new [] {
371
365
// A boolean column depicting the 'label'.
372
- new TextLoader .Column (" IsOver50k " , DataKind .BL , 0 ),
366
+ new TextLoader .Column (" IsOver50K " , DataKind .BL , 0 ),
373
367
// Three text columns.
374
368
new TextLoader .Column (" Workclass" , DataKind .TX , 1 ),
375
369
new TextLoader .Column (" Education" , DataKind .TX , 2 ),
376
370
new TextLoader .Column (" MaritalStatus" , DataKind .TX , 3 )
377
371
},
378
372
// First line of the file is a header, not a data row.
379
- HasHeader = true
380
- } );
373
+ hasHeader : true
374
+ );
381
375
382
376
// Start creating our processing pipeline. For now, let's just concatenate all the text columns
383
377
// together into one.
@@ -468,20 +462,18 @@ var mlContext = new MLContext();
468
462
469
463
// Step one: read the data as an IDataView.
470
464
// First, we define the reader: specify the data columns and where to find them in the text file.
471
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
472
- {
473
- Column = new [] {
465
+ var reader = mlContext .Data .TextReader (new [] {
474
466
// We read the first 11 values as a single float vector.
475
467
new TextLoader .Column (" FeatureVector" , DataKind .R4 , 0 , 10 ),
476
468
477
469
// Separately, read the target variable.
478
470
new TextLoader .Column (" Target" , DataKind .R4 , 11 ),
479
471
},
480
472
// First line of the file is a header, not a data row.
481
- HasHeader = true ,
473
+ hasHeader : true ,
482
474
// Default separator is tab, but we need a semicolon.
483
- Separator = " ; "
484
- } );
475
+ separatorChar : ';'
476
+ );
485
477
486
478
// Now read the file (remember though, readers are lazy, so the actual reading will happen when the data is accessed).
487
479
var trainData = reader .Read (trainDataPath );
@@ -617,9 +609,7 @@ var mlContext = new MLContext();
617
609
618
610
// Step one: read the data as an IDataView.
619
611
// First, we define the reader: specify the data columns and where to find them in the text file.
620
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
621
- {
622
- Column = new [] {
612
+ var reader = mlContext .Data .TextReader (new [] {
623
613
new TextLoader .Column (" SepalLength" , DataKind .R4 , 0 ),
624
614
new TextLoader .Column (" SepalWidth" , DataKind .R4 , 1 ),
625
615
new TextLoader .Column (" PetalLength" , DataKind .R4 , 2 ),
@@ -628,8 +618,8 @@ var reader = mlContext.Data.TextReader(new TextLoader.Arguments
628
618
new TextLoader .Column (" Label" , DataKind .TX , 4 ),
629
619
},
630
620
// Default separator is tab, but the dataset has comma.
631
- Separator = " , "
632
- } );
621
+ separatorChar : ','
622
+ );
633
623
634
624
// Retrieve the training data.
635
625
var trainData = reader .Read (irisDataPath );
@@ -910,17 +900,15 @@ You can achieve the same results using the dynamic API.
910
900
var mlContext = new MLContext ();
911
901
912
902
// Define the reader: specify the data columns and where to find them in the text file.
913
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
914
- {
915
- Column = new [] {
903
+ var reader = mlContext .Data .TextReader (new [] {
916
904
// The four features of the Iris dataset will be grouped together as one Features column.
917
905
new TextLoader .Column (" Features" , DataKind .R4 , 0 , 3 ),
918
906
// Label: kind of iris.
919
907
new TextLoader .Column (" Label" , DataKind .TX , 4 ),
920
908
},
921
909
// Default separator is tab, but the dataset has comma.
922
- Separator = " , "
923
- } );
910
+ separatorChar : ','
911
+ );
924
912
925
913
// Read the training data.
926
914
var trainData = reader .Read (dataPath );
@@ -1027,9 +1015,8 @@ You can achieve the same results using the dynamic API.
1027
1015
var mlContext = new MLContext ();
1028
1016
1029
1017
// Define the reader: specify the data columns and where to find them in the text file.
1030
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1031
- {
1032
- Column = new [] {
1018
+ var reader = mlContext .Data .TextReader (new []
1019
+ {
1033
1020
new TextLoader .Column (" Label" , DataKind .BL , 0 ),
1034
1021
// We will load all the categorical features into one vector column of size 8.
1035
1022
new TextLoader .Column (" CategoricalFeatures" , DataKind .TX , 1 , 8 ),
@@ -1038,8 +1025,8 @@ var reader = mlContext.Data.TextReader(new TextLoader.Arguments
1038
1025
// Let's also separately load the 'Workclass' column.
1039
1026
new TextLoader .Column (" Workclass" , DataKind .TX , 1 ),
1040
1027
},
1041
- HasHeader = true
1042
- } );
1028
+ hasHeader : true
1029
+ );
1043
1030
1044
1031
// Read the data.
1045
1032
var data = reader .Read (dataPath );
@@ -1154,14 +1141,13 @@ You can achieve the same results using the dynamic API.
1154
1141
var mlContext = new MLContext ();
1155
1142
1156
1143
// Define the reader: specify the data columns and where to find them in the text file.
1157
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1158
- {
1159
- Column = new [] {
1144
+ var reader = mlContext .Data .TextReader (new []
1145
+ {
1160
1146
new TextLoader .Column (" IsToxic" , DataKind .BL , 0 ),
1161
1147
new TextLoader .Column (" Message" , DataKind .TX , 1 ),
1162
1148
},
1163
- HasHeader = true
1164
- } );
1149
+ hasHeader : true
1150
+ );
1165
1151
1166
1152
// Read the data.
1167
1153
var data = reader .Read (dataPath );
@@ -1274,9 +1260,8 @@ var mlContext = new MLContext();
1274
1260
1275
1261
// Step one: read the data as an IDataView.
1276
1262
// First, we define the reader: specify the data columns and where to find them in the text file.
1277
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1278
- {
1279
- Column = new [] {
1263
+ var reader = mlContext .Data .TextReader (new []
1264
+ {
1280
1265
// We read the first 11 values as a single float vector.
1281
1266
new TextLoader .Column (" SepalLength" , DataKind .R4 , 0 ),
1282
1267
new TextLoader .Column (" SepalWidth" , DataKind .R4 , 1 ),
@@ -1286,8 +1271,8 @@ var reader = mlContext.Data.TextReader(new TextLoader.Arguments
1286
1271
new TextLoader .Column (" Label" , DataKind .TX , 4 ),
1287
1272
},
1288
1273
// Default separator is tab, but the dataset has comma.
1289
- Separator = " , "
1290
- } );
1274
+ separatorChar : ','
1275
+ );
1291
1276
1292
1277
// Read the data.
1293
1278
var data = reader .Read (dataPath );
0 commit comments