@@ -17,16 +17,28 @@ public static void Example()
1717 // Generate some data points.
1818 var examples = GenerateRandomDataPoints ( 10 ) ;
1919
20- // Convert the examples list to an IDataView object, which is consumable by ML.NET API.
20+ // Convert the examples list to an IDataView object, which is consumable
21+ // by ML.NET API.
2122 var dataview = mlContext . Data . LoadFromEnumerable ( examples ) ;
2223
23- // Cross validation splits your data randomly into set of "folds", and creates groups of Train and Test sets,
24- // where for each group, one fold is the Test and the rest of the folds the Train.
25- // So below, we specify Group column as the column containing the sampling keys.
26- // If we pass that column to cross validation it would be used to break data into certain chunks.
27- var folds = mlContext . Data . CrossValidationSplit ( dataview , numberOfFolds : 3 , samplingKeyColumnName : "Group" ) ;
28- var trainSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 0 ] . TrainSet , reuseRowObject : false ) ;
29- var testSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 0 ] . TestSet , reuseRowObject : false ) ;
24+ // Cross validation splits your data randomly into set of "folds", and
25+ // creates groups of Train and Test sets, where for each group, one fold
26+ // is the Test and the rest of the folds the Train. So below, we specify
27+ // Group column as the column containing the sampling keys. If we pass
28+ // that column to cross validation it would be used to break data into
29+ // certain chunks.
30+ var folds = mlContext . Data
31+ . CrossValidationSplit ( dataview , numberOfFolds : 3 ,
32+ samplingKeyColumnName : "Group" ) ;
33+
34+ var trainSet = mlContext . Data
35+ . CreateEnumerable < DataPoint > ( folds [ 0 ] . TrainSet ,
36+ reuseRowObject : false ) ;
37+
38+ var testSet = mlContext . Data
39+ . CreateEnumerable < DataPoint > ( folds [ 0 ] . TestSet ,
40+ reuseRowObject : false ) ;
41+
3042 PrintPreviewRows ( trainSet , testSet ) ;
3143
3244 // The data in the Train split.
@@ -43,8 +55,14 @@ public static void Example()
4355 // [Group, 0], [Features, 0.9060271]
4456 // [Group, 0], [Features, 0.2737045]
4557
46- trainSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 1 ] . TrainSet , reuseRowObject : false ) ;
47- testSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 1 ] . TestSet , reuseRowObject : false ) ;
58+ trainSet = mlContext . Data
59+ . CreateEnumerable < DataPoint > ( folds [ 1 ] . TrainSet ,
60+ reuseRowObject : false ) ;
61+
62+ testSet = mlContext . Data
63+ . CreateEnumerable < DataPoint > ( folds [ 1 ] . TestSet ,
64+ reuseRowObject : false ) ;
65+
4866 PrintPreviewRows ( trainSet , testSet ) ;
4967 // The data in the Train split.
5068 // [Group, 0], [Features, 0.7262433]
@@ -60,8 +78,14 @@ public static void Example()
6078 // [Group, 1], [Features, 0.2060332]
6179 // [Group, 1], [Features, 0.4421779]
6280
63- trainSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 2 ] . TrainSet , reuseRowObject : false ) ;
64- testSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 2 ] . TestSet , reuseRowObject : false ) ;
81+ trainSet = mlContext . Data
82+ . CreateEnumerable < DataPoint > ( folds [ 2 ] . TrainSet ,
83+ reuseRowObject : false ) ;
84+
85+ testSet = mlContext . Data
86+ . CreateEnumerable < DataPoint > ( folds [ 2 ] . TestSet ,
87+ reuseRowObject : false ) ;
88+
6589 PrintPreviewRows ( trainSet , testSet ) ;
6690 // The data in the Train split.
6791 // [Group, 0], [Features, 0.7262433]
@@ -79,8 +103,14 @@ public static void Example()
79103
80104 // Example of a split without specifying a sampling key column.
81105 folds = mlContext . Data . CrossValidationSplit ( dataview , numberOfFolds : 3 ) ;
82- trainSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 0 ] . TrainSet , reuseRowObject : false ) ;
83- testSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 0 ] . TestSet , reuseRowObject : false ) ;
106+ trainSet = mlContext . Data
107+ . CreateEnumerable < DataPoint > ( folds [ 0 ] . TrainSet ,
108+ reuseRowObject : false ) ;
109+
110+ testSet = mlContext . Data
111+ . CreateEnumerable < DataPoint > ( folds [ 0 ] . TestSet ,
112+ reuseRowObject : false ) ;
113+
84114 PrintPreviewRows ( trainSet , testSet ) ;
85115 // The data in the Train split.
86116 // [Group, 0], [Features, 0.7262433]
@@ -96,8 +126,14 @@ public static void Example()
96126 // [Group, 2], [Features, 0.5588848]
97127 // [Group, 0], [Features, 0.9060271]
98128
99- trainSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 1 ] . TrainSet , reuseRowObject : false ) ;
100- testSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 1 ] . TestSet , reuseRowObject : false ) ;
129+ trainSet = mlContext . Data
130+ . CreateEnumerable < DataPoint > ( folds [ 1 ] . TrainSet ,
131+ reuseRowObject : false ) ;
132+
133+ testSet = mlContext . Data
134+ . CreateEnumerable < DataPoint > ( folds [ 1 ] . TestSet ,
135+ reuseRowObject : false ) ;
136+
101137 PrintPreviewRows ( trainSet , testSet ) ;
102138 // The data in the Train split.
103139 // [Group, 2], [Features, 0.7680227]
@@ -113,8 +149,13 @@ public static void Example()
113149 // [Group, 2], [Features, 0.9775497]
114150 // [Group, 0], [Features, 0.2737045]
115151
116- trainSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 2 ] . TrainSet , reuseRowObject : false ) ;
117- testSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 2 ] . TestSet , reuseRowObject : false ) ;
152+ trainSet = mlContext . Data
153+ . CreateEnumerable < DataPoint > ( folds [ 2 ] . TrainSet ,
154+ reuseRowObject : false ) ;
155+
156+ testSet = mlContext . Data . CreateEnumerable < DataPoint > ( folds [ 2 ] . TestSet ,
157+ reuseRowObject : false ) ;
158+
118159 PrintPreviewRows ( trainSet , testSet ) ;
119160 // The data in the Train split.
120161 // [Group, 0], [Features, 0.7262433]
@@ -131,7 +172,9 @@ public static void Example()
131172 // [Group, 1], [Features, 0.4421779]
132173 }
133174
134- private static IEnumerable < DataPoint > GenerateRandomDataPoints ( int count , int seed = 0 )
175+ private static IEnumerable < DataPoint > GenerateRandomDataPoints ( int count ,
176+ int seed = 0 )
177+
135178 {
136179 var random = new Random ( seed ) ;
137180 for ( int i = 0 ; i < count ; i ++ )
@@ -146,7 +189,8 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int se
146189 }
147190 }
148191
149- // Example with features and group column. A data set is a collection of such examples.
192+ // Example with features and group column. A data set is a collection of
193+ // such examples.
150194 private class DataPoint
151195 {
152196 public float Group { get ; set ; }
@@ -155,7 +199,9 @@ private class DataPoint
155199 }
156200
157201 // print helper
158- private static void PrintPreviewRows ( IEnumerable < DataPoint > trainSet , IEnumerable < DataPoint > testSet )
202+ private static void PrintPreviewRows ( IEnumerable < DataPoint > trainSet ,
203+ IEnumerable < DataPoint > testSet )
204+
159205 {
160206
161207 Console . WriteLine ( $ "The data in the Train split.") ;
0 commit comments