Skip to content

Commit 81a5d39

Browse files
committed
cleaning up
1 parent 7f971b7 commit 81a5d39

File tree

3 files changed

+6
-38
lines changed

3 files changed

+6
-38
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/FastTree.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
5-
using System.Security.Cryptography;
6-
using System.Security.Cryptography.X509Certificates;
74
using Microsoft.ML;
85
using Microsoft.ML.Data;
96

@@ -12,10 +9,10 @@ namespace Samples.Dynamic.Trainers.Regression
129
public static class FastTreeRegression
1310
{
1411
// This example requires installation of additional NuGet package
15-
// <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>.
12+
// <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>.
1613
public static void Example()
1714
{
18-
// Create a new context for ML.NET operations. It can be used for exception tracking and logging,
15+
// Create a new context for ML.NET operations. It can be used for exception tracking and logging,
1916
// as a catalog of available operations and as the source of randomness.
2017
// Setting the seed to a fixed number in this example to make outputs deterministic.
2118
var mlContext = new MLContext(seed: 0);
@@ -26,25 +23,17 @@ public static void Example()
2623
// Convert the list of data points to an IDataView object, which is consumable by ML.NET API.
2724
var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints);
2825

29-
using (var f = File.OpenWrite("E:\\tmp\\data.txt"))
30-
mlContext.Data.SaveAsText(trainingData, f);
31-
3226
// Define the trainer.
33-
34-
var pipeline = mlContext.Data.CreateTextLoader<DataPoint>(hasHeader: true)
35-
.Append(mlContext.Regression.Trainers.FastTree(labelColumnName: nameof(DataPoint.Label),
36-
featureColumnName: nameof(DataPoint.Features)));
27+
var pipeline = mlContext.Regression.Trainers.FastTree(labelColumnName: nameof(DataPoint.Label), featureColumnName: nameof(DataPoint.Features));
3728

3829
// Train the model.
39-
var model = pipeline.Fit(new MultiFileSource(new[] { "E:\\tmp\\data.txt" }));
40-
41-
mlContext.Model.Save(model.Transformer, model.Loader, "E:\\tmp\\model.bin");
30+
var model = pipeline.Fit(trainingData);
4231

4332
// Create testing data. Use different random seed to make it different from training data.
4433
var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(5, seed: 123));
4534

4635
// Run the model on test data set.
47-
var transformedTestData = model.Transformer.Transform(testData);
36+
var transformedTestData = model.Transform(testData);
4837

4938
// Convert IDataView object to a list.
5039
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
@@ -89,10 +78,7 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int se
8978
// Example with label and 50 feature values. A data set is a collection of such examples.
9079
private class DataPoint
9180
{
92-
[LoadColumn(0)]
9381
public float Label { get; set; }
94-
95-
[LoadColumn(1, 50)]
9682
[VectorType(50)]
9783
public float[] Features { get; set; }
9884
}

docs/samples/Microsoft.ML.Samples/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
22
using System.Reflection;
3-
using Samples.Dynamic.Trainers.Regression;
43

54
namespace Microsoft.ML.Samples
65
{
76
public static class Program
87
{
9-
public static void Main(string[] args) => FastTreeRegression.Example();
8+
public static void Main(string[] args) => RunAll();
109

1110
internal static void RunAll()
1211
{

src/Microsoft.ML.FastTree/FastTree.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,23 +3276,6 @@ internal int GetLeaf(int treeId, in VBuffer<float> features, ref List<int> path)
32763276
return TrainedEnsemble.GetTreeAt(treeId).GetLeaf(in features, ref path);
32773277
}
32783278

3279-
//DataViewRow ICanGetSummaryAsIRow.GetSummaryIRowOrNull(RoleMappedSchema schema)
3280-
//{
3281-
// var names = default(VBuffer<ReadOnlyMemory<char>>);
3282-
// AnnotationUtils.GetSlotNames(schema, RoleMappedSchema.ColumnRole.Feature, NumFeatures, ref names);
3283-
// var metaBuilder = new DataViewSchema.Annotations.Builder();
3284-
// metaBuilder.AddSlotNames(NumFeatures, names.CopyTo);
3285-
3286-
// var weights = default(VBuffer<Single>);
3287-
// ((IHaveFeatureWeights)this).GetFeatureWeights(ref weights);
3288-
// var builder = new DataViewSchema.Annotations.Builder();
3289-
// builder.Add<VBuffer<float>>("Gains", new VectorDataViewType(NumberDataViewType.Single, NumFeatures), weights.CopyTo, metaBuilder.ToAnnotations());
3290-
3291-
// return AnnotationUtils.AnnotationsAsRow(builder.ToAnnotations());
3292-
//}
3293-
3294-
//DataViewRow ICanGetSummaryAsIRow.GetStatsIRowOrNull(RoleMappedSchema schema) => null;
3295-
32963279
private sealed class Tree : ITree<VBuffer<float>>
32973280
{
32983281
private readonly InternalRegressionTree _regTree;

0 commit comments

Comments
 (0)