@@ -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.
@@ -482,20 +476,18 @@ var mlContext = new MLContext();
482
476
483
477
// Step one: read the data as an IDataView.
484
478
// First, we define the reader: specify the data columns and where to find them in the text file.
485
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
486
- {
487
- Column = new [] {
479
+ var reader = mlContext .Data .TextReader (new [] {
488
480
// We read the first 11 values as a single float vector.
489
481
new TextLoader .Column (" FeatureVector" , DataKind .R4 , 0 , 10 ),
490
482
491
483
// Separately, read the target variable.
492
484
new TextLoader .Column (" Target" , DataKind .R4 , 11 ),
493
485
},
494
486
// First line of the file is a header, not a data row.
495
- HasHeader = true ,
487
+ hasHeader : true ,
496
488
// Default separator is tab, but we need a semicolon.
497
- Separator = " ; "
498
- } );
489
+ separatorChar : ';'
490
+ );
499
491
500
492
// Now read the file (remember though, readers are lazy, so the actual reading will happen when the data is accessed).
501
493
var trainData = reader .Read (trainDataPath );
@@ -653,9 +645,7 @@ var mlContext = new MLContext();
653
645
654
646
// Step one: read the data as an IDataView.
655
647
// First, we define the reader: specify the data columns and where to find them in the text file.
656
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
657
- {
658
- Column = new [] {
648
+ var reader = mlContext .Data .TextReader (new [] {
659
649
new TextLoader .Column (" SepalLength" , DataKind .R4 , 0 ),
660
650
new TextLoader .Column (" SepalWidth" , DataKind .R4 , 1 ),
661
651
new TextLoader .Column (" PetalLength" , DataKind .R4 , 2 ),
@@ -664,8 +654,8 @@ var reader = mlContext.Data.TextReader(new TextLoader.Arguments
664
654
new TextLoader .Column (" Label" , DataKind .TX , 4 ),
665
655
},
666
656
// Default separator is tab, but the dataset has comma.
667
- Separator = " , "
668
- } );
657
+ separatorChar : ','
658
+ );
669
659
670
660
// Retrieve the training data.
671
661
var trainData = reader .Read (irisDataPath );
@@ -952,17 +942,15 @@ You can achieve the same results using the dynamic API.
952
942
var mlContext = new MLContext ();
953
943
954
944
// Define the reader: specify the data columns and where to find them in the text file.
955
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
956
- {
957
- Column = new [] {
945
+ var reader = mlContext .Data .TextReader (new [] {
958
946
// The four features of the Iris dataset will be grouped together as one Features column.
959
947
new TextLoader .Column (" Features" , DataKind .R4 , 0 , 3 ),
960
948
// Label: kind of iris.
961
949
new TextLoader .Column (" Label" , DataKind .TX , 4 ),
962
950
},
963
951
// Default separator is tab, but the dataset has comma.
964
- Separator = " , "
965
- } );
952
+ separatorChar : ','
953
+ );
966
954
967
955
// Read the training data.
968
956
var trainData = reader .Read (dataPath );
@@ -1073,9 +1061,8 @@ You can achieve the same results using the dynamic API.
1073
1061
var mlContext = new MLContext ();
1074
1062
1075
1063
// Define the reader: specify the data columns and where to find them in the text file.
1076
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1077
- {
1078
- Column = new [] {
1064
+ var reader = mlContext .Data .TextReader (new []
1065
+ {
1079
1066
new TextLoader .Column (" Label" , DataKind .BL , 0 ),
1080
1067
// We will load all the categorical features into one vector column of size 8.
1081
1068
new TextLoader .Column (" CategoricalFeatures" , DataKind .TX , 1 , 8 ),
@@ -1084,8 +1071,8 @@ var reader = mlContext.Data.TextReader(new TextLoader.Arguments
1084
1071
// Let's also separately load the 'Workclass' column.
1085
1072
new TextLoader .Column (" Workclass" , DataKind .TX , 1 ),
1086
1073
},
1087
- HasHeader = true
1088
- } );
1074
+ hasHeader : true
1075
+ );
1089
1076
1090
1077
// Read the data.
1091
1078
var data = reader .Read (dataPath );
@@ -1207,14 +1194,13 @@ You can achieve the same results using the dynamic API.
1207
1194
var mlContext = new MLContext ();
1208
1195
1209
1196
// Define the reader: specify the data columns and where to find them in the text file.
1210
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1211
- {
1212
- Column = new [] {
1197
+ var reader = mlContext .Data .TextReader (new []
1198
+ {
1213
1199
new TextLoader .Column (" IsToxic" , DataKind .BL , 0 ),
1214
1200
new TextLoader .Column (" Message" , DataKind .TX , 1 ),
1215
1201
},
1216
- HasHeader = true
1217
- } );
1202
+ hasHeader : true
1203
+ );
1218
1204
1219
1205
// Read the data.
1220
1206
var data = reader .Read (dataPath );
@@ -1330,9 +1316,8 @@ var mlContext = new MLContext();
1330
1316
1331
1317
// Step one: read the data as an IDataView.
1332
1318
// First, we define the reader: specify the data columns and where to find them in the text file.
1333
- var reader = mlContext .Data .TextReader (new TextLoader .Arguments
1334
- {
1335
- Column = new [] {
1319
+ var reader = mlContext .Data .TextReader (new []
1320
+ {
1336
1321
// We read the first 11 values as a single float vector.
1337
1322
new TextLoader .Column (" SepalLength" , DataKind .R4 , 0 ),
1338
1323
new TextLoader .Column (" SepalWidth" , DataKind .R4 , 1 ),
@@ -1342,8 +1327,8 @@ var reader = mlContext.Data.TextReader(new TextLoader.Arguments
1342
1327
new TextLoader .Column (" Label" , DataKind .TX , 4 ),
1343
1328
},
1344
1329
// Default separator is tab, but the dataset has comma.
1345
- Separator = " , "
1346
- } );
1330
+ separatorChar : ','
1331
+ );
1347
1332
1348
1333
// Read the data.
1349
1334
var data = reader .Read (dataPath );
0 commit comments