From ab0853517da75111d91287b1ae2610513ab46caa Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Mon, 26 Nov 2018 17:01:55 -0800 Subject: [PATCH 01/12] Rename KMeansPredictor to KMeansModelParameters, rename namespace, and internalize interfaces except ICanSaveModel --- src/Microsoft.ML.Core/Data/IValueMapper.cs | 6 ++- .../Dirty/PredictorInterfaces.cs | 3 +- .../Scorers/SchemaBindablePredictorWrapper.cs | 2 +- .../KMeansCatalog.cs | 2 +- ...sPredictor.cs => KMeansModelParameters.cs} | 39 ++++++++++--------- .../KMeansPlusPlusTrainer.cs | 16 ++++---- .../KMeansStatic.cs | 4 +- .../AssemblyRegistration.cs | 4 +- src/Native/MatrixFactorizationNative/libmf | 2 +- .../Training.cs | 4 +- .../EnvironmentExtensions.cs | 4 +- .../TrainerEstimators/TrainerEstimators.cs | 2 +- 12 files changed, 47 insertions(+), 41 deletions(-) rename src/Microsoft.ML.KMeansClustering/{KMeansPredictor.cs => KMeansModelParameters.cs} (91%) diff --git a/src/Microsoft.ML.Core/Data/IValueMapper.cs b/src/Microsoft.ML.Core/Data/IValueMapper.cs index c6abfbc02d..d0b8d4b755 100644 --- a/src/Microsoft.ML.Core/Data/IValueMapper.cs +++ b/src/Microsoft.ML.Core/Data/IValueMapper.cs @@ -24,7 +24,8 @@ namespace Microsoft.ML.Runtime.Data /// type arguments for GetMapper, but typically contain additional information like /// vector lengths. /// - public interface IValueMapper + [BestFriend] + internal interface IValueMapper { ColumnType InputType { get; } ColumnType OutputType { get; } @@ -43,7 +44,8 @@ public interface IValueMapper /// type arguments for GetMapper, but typically contain additional information like /// vector lengths. /// - public interface IValueMapperDist : IValueMapper + [BestFriend] + internal interface IValueMapperDist : IValueMapper { ColumnType DistType { get; } diff --git a/src/Microsoft.ML.Data/Dirty/PredictorInterfaces.cs b/src/Microsoft.ML.Data/Dirty/PredictorInterfaces.cs index f866ca4817..af9eddb332 100644 --- a/src/Microsoft.ML.Data/Dirty/PredictorInterfaces.cs +++ b/src/Microsoft.ML.Data/Dirty/PredictorInterfaces.cs @@ -92,7 +92,8 @@ public interface ISampleableDistribution : IDistribution /// /// Predictors that can output themselves in a human-readable text format /// - public interface ICanSaveInTextFormat + [BestFriend] + internal interface ICanSaveInTextFormat { void SaveAsText(TextWriter writer, RoleMappedSchema schema); } diff --git a/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs b/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs index a2fdf96af4..8117aac935 100644 --- a/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs +++ b/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs @@ -41,7 +41,7 @@ public abstract class SchemaBindablePredictorWrapperBase : ISchemaBindableMapper // ValueMapper or FloatPredictor is non-null (or both). With these guarantees, // the score value type (_scoreType) can be determined. protected readonly IPredictor Predictor; - protected readonly IValueMapper ValueMapper; + internal readonly IValueMapper ValueMapper; protected readonly ColumnType ScoreType; bool ICanSavePfa.CanSavePfa => (ValueMapper as ICanSavePfa)?.CanSavePfa == true; diff --git a/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs b/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs index c096750ae0..6663fbbc6d 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs @@ -4,7 +4,7 @@ using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using System; namespace Microsoft.ML diff --git a/src/Microsoft.ML.KMeansClustering/KMeansPredictor.cs b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs similarity index 91% rename from src/Microsoft.ML.KMeansClustering/KMeansPredictor.cs rename to src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs index 38b5116da4..af8139fb75 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansPredictor.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs @@ -10,18 +10,18 @@ using Microsoft.ML.Runtime.Internal.Utilities; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime.Model; using Microsoft.ML.Runtime.Model.Onnx; using Microsoft.ML.Runtime.Internal.Internallearn; using System.Collections.Generic; -[assembly: LoadableClass(typeof(KMeansPredictor), null, typeof(SignatureLoadModel), - "KMeans predictor", KMeansPredictor.LoaderSignature)] +[assembly: LoadableClass(typeof(KMeansModelParameters), null, typeof(SignatureLoadModel), + "KMeans predictor", KMeansModelParameters.LoaderSignature)] -namespace Microsoft.ML.Trainers.KMeans +namespace Microsoft.ML.KMeansClustering { - public sealed class KMeansPredictor : + public sealed class KMeansModelParameters : PredictorBase>, IValueMapper, ICanSaveInTextFormat, @@ -42,12 +42,15 @@ private static VersionInfo GetVersionInfo() verReadableCur: 0x00010002, verWeCanReadBack: 0x00010001, loaderSignature: LoaderSignature, - loaderAssemblyName: typeof(KMeansPredictor).Assembly.FullName); + loaderAssemblyName: typeof(KMeansModelParameters).Assembly.FullName); } public override PredictionKind PredictionKind => PredictionKind.Clustering; - public ColumnType InputType { get; } - public ColumnType OutputType { get; } + + private readonly ColumnType _inputType; + private readonly ColumnType _outputType; + ColumnType IValueMapper.InputType => _inputType; + ColumnType IValueMapper.OutputType => _outputType; bool ICanSaveOnnx.CanSaveOnnx(OnnxContext ctx) => true; @@ -66,7 +69,7 @@ private static VersionInfo GetVersionInfo() /// a deep copy, if false then this constructor will take ownership of the passed in centroid vectors. /// If false then the caller must take care to not use or modify the input vectors once this object /// is constructed, and should probably remove all references. - public KMeansPredictor(IHostEnvironment env, int k, VBuffer[] centroids, bool copyIn) + public KMeansModelParameters(IHostEnvironment env, int k, VBuffer[] centroids, bool copyIn) : base(env, LoaderSignature) { Host.CheckParam(k > 0, nameof(k), "Need at least one cluster"); @@ -92,8 +95,8 @@ public KMeansPredictor(IHostEnvironment env, int k, VBuffer[] centroids, InitPredictor(); - InputType = new VectorType(NumberType.Float, _dimensionality); - OutputType = new VectorType(NumberType.Float, _k); + _inputType = new VectorType(NumberType.Float, _dimensionality); + _outputType = new VectorType(NumberType.Float, _k); } /// @@ -101,7 +104,7 @@ public KMeansPredictor(IHostEnvironment env, int k, VBuffer[] centroids, /// /// The load context /// The host environment - private KMeansPredictor(IHostEnvironment env, ModelLoadContext ctx) + private KMeansModelParameters(IHostEnvironment env, ModelLoadContext ctx) : base(env, LoaderSignature, ctx) { // *** Binary format *** @@ -134,11 +137,11 @@ private KMeansPredictor(IHostEnvironment env, ModelLoadContext ctx) InitPredictor(); - InputType = new VectorType(NumberType.Float, _dimensionality); - OutputType = new VectorType(NumberType.Float, _k); + _inputType = new VectorType(NumberType.Float, _dimensionality); + _outputType = new VectorType(NumberType.Float, _k); } - public ValueMapper GetMapper() + ValueMapper IValueMapper.GetMapper() { Host.Check(typeof(TIn) == typeof(VBuffer)); Host.Check(typeof(TOut) == typeof(VBuffer)); @@ -169,7 +172,7 @@ private void Map(in VBuffer src, Span distances) } } - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { writer.WriteLine("K: {0}", _k); writer.WriteLine("Dimensionality: {0}", _dimensionality); @@ -247,12 +250,12 @@ protected override void SaveCore(ModelSaveContext ctx) /// /// This method is called by reflection to instantiate a predictor. /// - public static KMeansPredictor Create(IHostEnvironment env, ModelLoadContext ctx) + private static KMeansModelParameters Create(IHostEnvironment env, ModelLoadContext ctx) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(ctx, nameof(ctx)); ctx.CheckAtModel(GetVersionInfo()); - return new KMeansPredictor(env, ctx); + return new KMeansModelParameters(env, ctx); } /// diff --git a/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs b/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs index 41084bd5ab..8b85749a5a 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs @@ -13,7 +13,7 @@ using Microsoft.ML.Runtime.Internal.Utilities; using Microsoft.ML.Runtime.Numeric; using Microsoft.ML.Runtime.Training; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using System; using System.Linq; using System.Threading.Tasks; @@ -26,10 +26,10 @@ [assembly: LoadableClass(typeof(void), typeof(KMeansPlusPlusTrainer), null, typeof(SignatureEntryPointModule), "KMeans")] -namespace Microsoft.ML.Trainers.KMeans +namespace Microsoft.ML.KMeansClustering { /// - public class KMeansPlusPlusTrainer : TrainerEstimatorBase, KMeansPredictor> + public class KMeansPlusPlusTrainer : TrainerEstimatorBase, KMeansModelParameters> { public const string LoadNameValue = "KMeansPlusPlus"; internal const string UserNameValue = "KMeans++ Clustering"; @@ -151,7 +151,7 @@ private KMeansPlusPlusTrainer(IHostEnvironment env, Arguments args, Action MakeTransformer(KMeansPredictor model, Schema trainSchema) - => new ClusteringPredictionTransformer(Host, model, trainSchema, _featureColumn); + protected override ClusteringPredictionTransformer MakeTransformer(KMeansModelParameters model, Schema trainSchema) + => new ClusteringPredictionTransformer(Host, model, trainSchema, _featureColumn); } internal static class KMeansPlusPlusInit diff --git a/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs b/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs index f5fe8a91d9..077755e32b 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs @@ -4,7 +4,7 @@ using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.StaticPipe.Runtime; using System; @@ -33,7 +33,7 @@ public static (Vector score, Key predictedLabel) KMeans(this Cluste Vector features, Scalar weights = null, int clustersCount = KMeansPlusPlusTrainer.Defaults.K, Action advancedSettings = null, - Action onFit = null) + Action onFit = null) { Contracts.CheckValue(features, nameof(features)); Contracts.CheckValueOrNull(weights); diff --git a/src/Microsoft.ML.Legacy/AssemblyRegistration.cs b/src/Microsoft.ML.Legacy/AssemblyRegistration.cs index 448395769a..6f561bdabd 100644 --- a/src/Microsoft.ML.Legacy/AssemblyRegistration.cs +++ b/src/Microsoft.ML.Legacy/AssemblyRegistration.cs @@ -5,7 +5,7 @@ using Microsoft.ML.Runtime.Api; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Trainers.FastTree; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Runtime.Sweeper; using Microsoft.ML.Runtime.Tools; @@ -44,7 +44,7 @@ private static bool LoadStandardAssemblies() _ = typeof(TextLoader).Assembly; // ML.Data //_ = typeof(EnsemblePredictor).Assembly); // ML.Ensemble BUG https://github.com/dotnet/machinelearning/issues/1078 Ensemble isn't in a NuGet package _ = typeof(FastTreeBinaryPredictor).Assembly; // ML.FastTree - _ = typeof(KMeansPredictor).Assembly; // ML.KMeansClustering + _ = typeof(KMeansModelParameters).Assembly; // ML.KMeansClustering _ = typeof(Maml).Assembly; // ML.Maml _ = typeof(PcaPredictor).Assembly; // ML.PCA _ = typeof(SweepCommand).Assembly; // ML.Sweeper diff --git a/src/Native/MatrixFactorizationNative/libmf b/src/Native/MatrixFactorizationNative/libmf index f92a18161b..1ecc365249 160000 --- a/src/Native/MatrixFactorizationNative/libmf +++ b/src/Native/MatrixFactorizationNative/libmf @@ -1 +1 @@ -Subproject commit f92a18161b6824fda4c4ab698a69d299a836841a +Subproject commit 1ecc365249e5cac5e72c66317a141298dc52f6e3 diff --git a/test/Microsoft.ML.StaticPipelineTesting/Training.cs b/test/Microsoft.ML.StaticPipelineTesting/Training.cs index b59c2118b5..50d19658cd 100644 --- a/test/Microsoft.ML.StaticPipelineTesting/Training.cs +++ b/test/Microsoft.ML.StaticPipelineTesting/Training.cs @@ -8,7 +8,7 @@ using Microsoft.ML.Trainers.FastTree; using Microsoft.ML.Runtime.Internal.Calibration; using Microsoft.ML.Runtime.Internal.Internallearn; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime.Learners; using Microsoft.ML.Runtime.LightGBM; using Microsoft.ML.Runtime.RunTests; @@ -676,7 +676,7 @@ public void KMeans() var reader = TextLoader.CreateReader(env, c => (label: c.LoadText(0), features: c.LoadFloat(1, 4))); - KMeansPredictor pred = null; + KMeansModelParameters pred = null; var est = reader.MakeNewEstimator() .Append(r => (label: r.label.ToKey(), r.features)) diff --git a/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs b/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs index 13a78fdf3f..867c1ff476 100644 --- a/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs +++ b/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs @@ -7,7 +7,7 @@ using Microsoft.ML.Runtime.Ensemble; using Microsoft.ML.Runtime.Learners; using Microsoft.ML.Trainers.FastTree; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; @@ -23,7 +23,7 @@ public static TEnvironment AddStandardComponents(this TEnvironment env.ComponentCatalog.RegisterAssembly(typeof(OneHotEncodingTransformer).Assembly); // ML.Transforms env.ComponentCatalog.RegisterAssembly(typeof(FastTreeBinaryPredictor).Assembly); // ML.FastTree env.ComponentCatalog.RegisterAssembly(typeof(EnsemblePredictor).Assembly); // ML.Ensemble - env.ComponentCatalog.RegisterAssembly(typeof(KMeansPredictor).Assembly); // ML.KMeansClustering + env.ComponentCatalog.RegisterAssembly(typeof(KMeansModelParameters).Assembly); // ML.KMeansClustering env.ComponentCatalog.RegisterAssembly(typeof(PcaPredictor).Assembly); // ML.PCA env.ComponentCatalog.RegisterAssembly(typeof(Experiment).Assembly); // ML.Legacy return env; diff --git a/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs b/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs index 1ac7c28622..30fb77cf62 100644 --- a/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs +++ b/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs @@ -6,7 +6,7 @@ using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.RunTests; using Microsoft.ML.Trainers; -using Microsoft.ML.Trainers.KMeans; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; using Microsoft.ML.Transforms.Text; From cbb92f6add2df1bb642df06c1ddb8bbb3de9ffd6 Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 27 Nov 2018 13:17:18 -0800 Subject: [PATCH 02/12] Internalizing SaveCore --- src/Microsoft.ML.Data/Dirty/PredictorBase.cs | 3 ++- .../Scorers/SchemaBindablePredictorWrapper.cs | 2 +- .../Trainer/EnsembleDistributionPredictor.cs | 2 +- src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictor.cs | 2 +- .../Trainer/EnsemblePredictorBase.cs | 2 +- .../Trainer/Multiclass/EnsembleMultiClassPredictor.cs | 2 +- src/Microsoft.ML.FastTree/FastTree.cs | 2 +- src/Microsoft.ML.FastTree/FastTreeClassification.cs | 2 +- src/Microsoft.ML.FastTree/FastTreeRanking.cs | 2 +- src/Microsoft.ML.FastTree/FastTreeRegression.cs | 2 +- src/Microsoft.ML.FastTree/FastTreeTweedie.cs | 2 +- src/Microsoft.ML.FastTree/RandomForestClassification.cs | 2 +- src/Microsoft.ML.FastTree/RandomForestRegression.cs | 2 +- src/Microsoft.ML.HalLearners/OlsLinearRegression.cs | 2 +- .../KMeansModelParameters.cs | 6 +++--- src/Microsoft.ML.LightGBM/LightGbmBinaryTrainer.cs | 2 +- src/Microsoft.ML.LightGBM/LightGbmRankingTrainer.cs | 2 +- src/Microsoft.ML.LightGBM/LightGbmRegressionTrainer.cs | 2 +- src/Microsoft.ML.PCA/PcaTrainer.cs | 2 +- .../FieldAwareFactorizationMachinePredictor.cs | 2 +- .../Standard/LinearPredictor.cs | 9 +++++---- .../LogisticRegression/MulticlassLogisticRegression.cs | 2 +- .../Standard/MultiClass/MultiClassNaiveBayesTrainer.cs | 2 +- .../Standard/MultiClass/Ova.cs | 2 +- .../Standard/MultiClass/Pkpd.cs | 2 +- .../Standard/Simple/SimpleTrainers.cs | 4 ++-- 26 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/Microsoft.ML.Data/Dirty/PredictorBase.cs b/src/Microsoft.ML.Data/Dirty/PredictorBase.cs index 0d73db05fc..fe27705ff8 100644 --- a/src/Microsoft.ML.Data/Dirty/PredictorBase.cs +++ b/src/Microsoft.ML.Data/Dirty/PredictorBase.cs @@ -53,7 +53,8 @@ public virtual void Save(ModelSaveContext ctx) SaveCore(ctx); } - protected virtual void SaveCore(ModelSaveContext ctx) + [BestFriend] + private protected virtual void SaveCore(ModelSaveContext ctx) { Contracts.AssertValue(ctx); diff --git a/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs b/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs index 8117aac935..248e7936c8 100644 --- a/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs +++ b/src/Microsoft.ML.Data/Scorers/SchemaBindablePredictorWrapper.cs @@ -41,7 +41,7 @@ public abstract class SchemaBindablePredictorWrapperBase : ISchemaBindableMapper // ValueMapper or FloatPredictor is non-null (or both). With these guarantees, // the score value type (_scoreType) can be determined. protected readonly IPredictor Predictor; - internal readonly IValueMapper ValueMapper; + private protected readonly IValueMapper ValueMapper; protected readonly ColumnType ScoreType; bool ICanSavePfa.CanSavePfa => (ValueMapper as ICanSavePfa)?.CanSavePfa == true; diff --git a/src/Microsoft.ML.Ensemble/Trainer/EnsembleDistributionPredictor.cs b/src/Microsoft.ML.Ensemble/Trainer/EnsembleDistributionPredictor.cs index 5a92512e6d..6346abfc80 100644 --- a/src/Microsoft.ML.Ensemble/Trainer/EnsembleDistributionPredictor.cs +++ b/src/Microsoft.ML.Ensemble/Trainer/EnsembleDistributionPredictor.cs @@ -109,7 +109,7 @@ public static EnsembleDistributionPredictor Create(IHostEnvironment env, ModelLo return new EnsembleDistributionPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictor.cs b/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictor.cs index b69b76f40e..30b2dce057 100644 --- a/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictor.cs +++ b/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictor.cs @@ -99,7 +99,7 @@ public static EnsemblePredictor Create(IHostEnvironment env, ModelLoadContext ct return new EnsemblePredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs b/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs index 032312acde..1cedd9ec1c 100644 --- a/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs +++ b/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs @@ -86,7 +86,7 @@ protected EnsemblePredictorBase(IHostEnvironment env, string name, ModelLoadCont ctx.LoadModel, SignatureLoadModel>(Host, out Combiner, @"Combiner"); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); diff --git a/src/Microsoft.ML.Ensemble/Trainer/Multiclass/EnsembleMultiClassPredictor.cs b/src/Microsoft.ML.Ensemble/Trainer/Multiclass/EnsembleMultiClassPredictor.cs index 6f931f3e9c..a332d3ddb0 100644 --- a/src/Microsoft.ML.Ensemble/Trainer/Multiclass/EnsembleMultiClassPredictor.cs +++ b/src/Microsoft.ML.Ensemble/Trainer/Multiclass/EnsembleMultiClassPredictor.cs @@ -95,7 +95,7 @@ public static EnsembleMultiClassPredictor Create(IHostEnvironment env, ModelLoad return new EnsembleMultiClassPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.FastTree/FastTree.cs b/src/Microsoft.ML.FastTree/FastTree.cs index 21a5737944..5e5a2a7900 100644 --- a/src/Microsoft.ML.FastTree/FastTree.cs +++ b/src/Microsoft.ML.FastTree/FastTree.cs @@ -2891,7 +2891,7 @@ protected FastTreePredictionWrapper(IHostEnvironment env, string name, ModelLoad InputType = new VectorType(NumberType.Float, NumFeatures); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); diff --git a/src/Microsoft.ML.FastTree/FastTreeClassification.cs b/src/Microsoft.ML.FastTree/FastTreeClassification.cs index e628c0dce9..da89d8394f 100644 --- a/src/Microsoft.ML.FastTree/FastTreeClassification.cs +++ b/src/Microsoft.ML.FastTree/FastTreeClassification.cs @@ -79,7 +79,7 @@ private FastTreeBinaryPredictor(IHostEnvironment env, ModelLoadContext ctx) { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.FastTree/FastTreeRanking.cs b/src/Microsoft.ML.FastTree/FastTreeRanking.cs index af4c90a20b..b3967ef5db 100644 --- a/src/Microsoft.ML.FastTree/FastTreeRanking.cs +++ b/src/Microsoft.ML.FastTree/FastTreeRanking.cs @@ -1125,7 +1125,7 @@ private FastTreeRankingPredictor(IHostEnvironment env, ModelLoadContext ctx) { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.FastTree/FastTreeRegression.cs b/src/Microsoft.ML.FastTree/FastTreeRegression.cs index 1ba21904c0..a101284957 100644 --- a/src/Microsoft.ML.FastTree/FastTreeRegression.cs +++ b/src/Microsoft.ML.FastTree/FastTreeRegression.cs @@ -474,7 +474,7 @@ private FastTreeRegressionPredictor(IHostEnvironment env, ModelLoadContext ctx) { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.FastTree/FastTreeTweedie.cs b/src/Microsoft.ML.FastTree/FastTreeTweedie.cs index 45668b56a9..65f6151ea6 100644 --- a/src/Microsoft.ML.FastTree/FastTreeTweedie.cs +++ b/src/Microsoft.ML.FastTree/FastTreeTweedie.cs @@ -477,7 +477,7 @@ private FastTreeTweediePredictor(IHostEnvironment env, ModelLoadContext ctx) { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.FastTree/RandomForestClassification.cs b/src/Microsoft.ML.FastTree/RandomForestClassification.cs index 9b7f4f78b1..e70713f515 100644 --- a/src/Microsoft.ML.FastTree/RandomForestClassification.cs +++ b/src/Microsoft.ML.FastTree/RandomForestClassification.cs @@ -88,7 +88,7 @@ private FastForestClassificationPredictor(IHostEnvironment env, ModelLoadContext { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.FastTree/RandomForestRegression.cs b/src/Microsoft.ML.FastTree/RandomForestRegression.cs index a5fec96249..ab7e0f362b 100644 --- a/src/Microsoft.ML.FastTree/RandomForestRegression.cs +++ b/src/Microsoft.ML.FastTree/RandomForestRegression.cs @@ -76,7 +76,7 @@ private FastForestRegressionPredictor(IHostEnvironment env, ModelLoadContext ctx _quantileSampleCount = ctx.Reader.ReadInt32(); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs b/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs index 33eecb3b65..ffb061f6b7 100644 --- a/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs +++ b/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs @@ -682,7 +682,7 @@ private OlsLinearRegressionPredictor(IHostEnvironment env, ModelLoadContext ctx) ProbCheckDecode(_pValues[i]); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs index af8139fb75..cdb79c4074 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs @@ -28,7 +28,7 @@ public sealed class KMeansModelParameters : ICanSaveModel, ISingleCanSaveOnnx { - public const string LoaderSignature = "KMeansPredictor"; + internal const string LoaderSignature = "KMeansPredictor"; /// /// Version information to be saved in binary format @@ -45,7 +45,7 @@ private static VersionInfo GetVersionInfo() loaderAssemblyName: typeof(KMeansModelParameters).Assembly.FullName); } - public override PredictionKind PredictionKind => PredictionKind.Clustering; + private override PredictionKind PredictionKind => PredictionKind.Clustering; private readonly ColumnType _inputType; private readonly ColumnType _outputType; @@ -218,7 +218,7 @@ void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) /// Save the predictor in binary format. /// /// The context to save to - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.LightGBM/LightGbmBinaryTrainer.cs b/src/Microsoft.ML.LightGBM/LightGbmBinaryTrainer.cs index ffec7f10ee..159e32ec56 100644 --- a/src/Microsoft.ML.LightGBM/LightGbmBinaryTrainer.cs +++ b/src/Microsoft.ML.LightGBM/LightGbmBinaryTrainer.cs @@ -65,7 +65,7 @@ private LightGbmBinaryPredictor(IHostEnvironment env, ModelLoadContext ctx) { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.LightGBM/LightGbmRankingTrainer.cs b/src/Microsoft.ML.LightGBM/LightGbmRankingTrainer.cs index e7f76bf215..ba998b8545 100644 --- a/src/Microsoft.ML.LightGBM/LightGbmRankingTrainer.cs +++ b/src/Microsoft.ML.LightGBM/LightGbmRankingTrainer.cs @@ -61,7 +61,7 @@ private LightGbmRankingPredictor(IHostEnvironment env, ModelLoadContext ctx) { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.LightGBM/LightGbmRegressionTrainer.cs b/src/Microsoft.ML.LightGBM/LightGbmRegressionTrainer.cs index f59d289e3a..062e994520 100644 --- a/src/Microsoft.ML.LightGBM/LightGbmRegressionTrainer.cs +++ b/src/Microsoft.ML.LightGBM/LightGbmRegressionTrainer.cs @@ -61,7 +61,7 @@ private LightGbmRegressionPredictor(IHostEnvironment env, ModelLoadContext ctx) { } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.PCA/PcaTrainer.cs b/src/Microsoft.ML.PCA/PcaTrainer.cs index f6ab01820f..8598fce92c 100644 --- a/src/Microsoft.ML.PCA/PcaTrainer.cs +++ b/src/Microsoft.ML.PCA/PcaTrainer.cs @@ -462,7 +462,7 @@ private PcaPredictor(IHostEnvironment env, ModelLoadContext ctx) _inputType = new VectorType(NumberType.Float, _dimension); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.StandardLearners/FactorizationMachine/FieldAwareFactorizationMachinePredictor.cs b/src/Microsoft.ML.StandardLearners/FactorizationMachine/FieldAwareFactorizationMachinePredictor.cs index 91e57b13a9..7c818102bc 100644 --- a/src/Microsoft.ML.StandardLearners/FactorizationMachine/FieldAwareFactorizationMachinePredictor.cs +++ b/src/Microsoft.ML.StandardLearners/FactorizationMachine/FieldAwareFactorizationMachinePredictor.cs @@ -120,7 +120,7 @@ public static FieldAwareFactorizationMachinePredictor Create(IHostEnvironment en return new FieldAwareFactorizationMachinePredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { Host.AssertValue(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs b/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs index 5f3c0c72cc..01c53890ad 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs @@ -185,7 +185,8 @@ protected LinearPredictor(IHostEnvironment env, string name, ModelLoadContext ct _weightsDenseLock = new object(); } - protected override void SaveCore(ModelSaveContext ctx) + [BestFriend] + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); @@ -459,7 +460,7 @@ public static IPredictorProducing Create(IHostEnvironment env, ModelLoadC return new SchemaBindableCalibratedPredictor(env, predictor, calibrator); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { // *** Binary format *** // (Base class) @@ -613,7 +614,7 @@ public static LinearRegressionPredictor Create(IHostEnvironment env, ModelLoadCo return new LinearRegressionPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); @@ -689,7 +690,7 @@ public static PoissonRegressionPredictor Create(IHostEnvironment env, ModelLoadC return new PoissonRegressionPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs b/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs index af41587e33..156abe3828 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs @@ -567,7 +567,7 @@ public static MulticlassLogisticRegressionPredictor Create(IHostEnvironment env, return new MulticlassLogisticRegressionPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs index 43ddb8a355..8876e420aa 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs @@ -306,7 +306,7 @@ public static MultiClassNaiveBayesPredictor Create(IHostEnvironment env, ModelLo return new MultiClassNaiveBayesPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs index a8894f9149..a2263ab876 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs @@ -323,7 +323,7 @@ private static void LoadPredictors(IHostEnvironment env, TPredictor[ ctx.LoadModel(env, out predictors[i], string.Format(SubPredictorFmt, i)); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs index 9f5ab8ea3c..3d15fff849 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs @@ -337,7 +337,7 @@ public static PkpdPredictor Create(IHostEnvironment env, ModelLoadContext ctx) return new PkpdPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); diff --git a/src/Microsoft.ML.StandardLearners/Standard/Simple/SimpleTrainers.cs b/src/Microsoft.ML.StandardLearners/Standard/Simple/SimpleTrainers.cs index ec39fc1e1c..eaa45068f7 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/Simple/SimpleTrainers.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/Simple/SimpleTrainers.cs @@ -172,7 +172,7 @@ public static RandomPredictor Create(IHostEnvironment env, ModelLoadContext ctx) /// Save the predictor in the binary format. /// /// - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); @@ -395,7 +395,7 @@ public static PriorPredictor Create(IHostEnvironment env, ModelLoadContext ctx) return new PriorPredictor(env, ctx); } - protected override void SaveCore(ModelSaveContext ctx) + private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); ctx.SetVersionInfo(GetVersionInfo()); From bbf1dff1524b26ad05a2b2aec5a3049b1b26cc78 Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 27 Nov 2018 14:28:31 -0800 Subject: [PATCH 03/12] Adding sample --- .../Microsoft.ML.Samples/Dynamic/KMeans.cs | 50 +++++++++++++++++++ .../Microsoft.ML.Samples.csproj | 1 + .../KMeansModelParameters.cs | 3 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs new file mode 100644 index 0000000000..5126571724 --- /dev/null +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs @@ -0,0 +1,50 @@ +using Microsoft.ML.Runtime.Api; +using Microsoft.ML.Runtime.Data; +using Microsoft.ML.KMeansClustering; +using Microsoft.ML.Transforms; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.ML.Samples.Dynamic +{ + public class KMeans_example + { + public static void KMeans() + { + // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, + // as well as the source of randomness. + var ml = new MLContext(); + + // Get a small dataset as an IEnumerable and convert it to an IDataView. + IEnumerable data = SamplesUtils.DatasetUtils.GetInfertData(); + var trainData = ml.CreateStreamingDataView(data); + + // Preview of the data. + // + // Age Case Education Induced Parity PooledStratum RowNum ... + // 26 1 0-5yrs 1 6 3 1 ... + // 42 1 0-5yrs 1 1 1 2 ... + // 39 1 0-5yrs 2 6 4 3 ... + // 34 1 0-5yrs 2 4 2 4 ... + // 35 1 6-11yrs 1 3 32 5 ... + + // A pipeline for concatenating the age, parity and induced columns together in the Features column and training a KMeans model on them. + string outputColumnName = "Features"; + var pipeline = ml.Transforms.Concatenate(outputColumnName, new[] { "Age", "Parity", "Induced" }) + .Append(ml.Clustering.Trainers.KMeans(outputColumnName, clustersCount: 2)); + + var model = pipeline.Fit(trainData); + + // Get centroids and k from KMeansModelParameters. + VBuffer[] centroids = default; + int k; + + var modelParams = model.LastTransformer.Model; + modelParams.GetClusterCentroids(ref centroids, out k); + + var centroid = centroids[0].GetValues(); + Console.WriteLine("The coordinates of centroid 0 are: " + string.Join(", ", centroid.ToArray())); + } + } +} diff --git a/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj b/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj index 6b3d9f957b..a8002fe9bf 100644 --- a/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj +++ b/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj @@ -7,6 +7,7 @@ + diff --git a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs index cdb79c4074..ed2211edfd 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs @@ -45,7 +45,8 @@ private static VersionInfo GetVersionInfo() loaderAssemblyName: typeof(KMeansModelParameters).Assembly.FullName); } - private override PredictionKind PredictionKind => PredictionKind.Clustering; + // REVIEW: Leaving this public for now until we figure out the correct way to remove it. + public override PredictionKind PredictionKind => PredictionKind.Clustering; private readonly ColumnType _inputType; private readonly ColumnType _outputType; From 28347a3c4d8a14d3b759adc03b7c66e9ab5df80c Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 27 Nov 2018 15:44:52 -0800 Subject: [PATCH 04/12] BestFriend attribute for the correct method overridden by LightGbmBinaryPredictor.SaveCore --- docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs | 3 --- src/Microsoft.ML.FastTree/FastTree.cs | 1 + src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs | 2 +- .../KMeansModelParameters.cs | 12 ++++++------ .../KMeansPlusPlusTrainer.cs | 2 +- src/Microsoft.ML.KMeansClustering/KMeansStatic.cs | 2 +- src/Microsoft.ML.Legacy/AssemblyRegistration.cs | 6 +++--- test/Microsoft.ML.StaticPipelineTesting/Training.cs | 2 +- .../EnvironmentExtensions.cs | 2 +- .../TrainerEstimators/TrainerEstimators.cs | 2 +- 10 files changed, 16 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs index 5126571724..809459d4b5 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs @@ -1,10 +1,7 @@ using Microsoft.ML.Runtime.Api; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.KMeansClustering; -using Microsoft.ML.Transforms; using System; using System.Collections.Generic; -using System.Text; namespace Microsoft.ML.Samples.Dynamic { diff --git a/src/Microsoft.ML.FastTree/FastTree.cs b/src/Microsoft.ML.FastTree/FastTree.cs index 5e5a2a7900..1a492ff0bf 100644 --- a/src/Microsoft.ML.FastTree/FastTree.cs +++ b/src/Microsoft.ML.FastTree/FastTree.cs @@ -2891,6 +2891,7 @@ protected FastTreePredictionWrapper(IHostEnvironment env, string name, ModelLoad InputType = new VectorType(NumberType.Float, NumFeatures); } + [BestFriend] private protected override void SaveCore(ModelSaveContext ctx) { base.SaveCore(ctx); diff --git a/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs b/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs index 6663fbbc6d..939ab92579 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.KMeansClustering; using System; namespace Microsoft.ML diff --git a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs index ed2211edfd..23b64dd4ba 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs @@ -4,16 +4,16 @@ using Float = System.Single; -using System; -using System.IO; -using Microsoft.ML.Runtime.Numeric; -using Microsoft.ML.Runtime.Internal.Utilities; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.KMeansClustering; +using Microsoft.ML.Runtime.Internal.Internallearn; +using Microsoft.ML.Runtime.Internal.Utilities; using Microsoft.ML.Runtime.Model; using Microsoft.ML.Runtime.Model.Onnx; -using Microsoft.ML.Runtime.Internal.Internallearn; +using Microsoft.ML.Runtime.Numeric; +using System; +using System.IO; using System.Collections.Generic; [assembly: LoadableClass(typeof(KMeansModelParameters), null, typeof(SignatureLoadModel), diff --git a/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs b/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs index 8b85749a5a..5f3de7b04a 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs @@ -4,6 +4,7 @@ using Microsoft.ML.Core.Data; using Microsoft.ML.Data; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.CommandLine; using Microsoft.ML.Runtime.Data; @@ -13,7 +14,6 @@ using Microsoft.ML.Runtime.Internal.Utilities; using Microsoft.ML.Runtime.Numeric; using Microsoft.ML.Runtime.Training; -using Microsoft.ML.KMeansClustering; using System; using System.Linq; using System.Threading.Tasks; diff --git a/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs b/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs index 077755e32b..eb27c9fef2 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.KMeansClustering; using Microsoft.ML.StaticPipe.Runtime; using System; diff --git a/src/Microsoft.ML.Legacy/AssemblyRegistration.cs b/src/Microsoft.ML.Legacy/AssemblyRegistration.cs index 6f561bdabd..0c927b53b8 100644 --- a/src/Microsoft.ML.Legacy/AssemblyRegistration.cs +++ b/src/Microsoft.ML.Legacy/AssemblyRegistration.cs @@ -2,13 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime.Api; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.Trainers.FastTree; -using Microsoft.ML.KMeansClustering; -using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Runtime.Sweeper; using Microsoft.ML.Runtime.Tools; +using Microsoft.ML.Trainers.FastTree; +using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; using System; using System.Reflection; diff --git a/test/Microsoft.ML.StaticPipelineTesting/Training.cs b/test/Microsoft.ML.StaticPipelineTesting/Training.cs index 50d19658cd..4e485592e9 100644 --- a/test/Microsoft.ML.StaticPipelineTesting/Training.cs +++ b/test/Microsoft.ML.StaticPipelineTesting/Training.cs @@ -5,10 +5,10 @@ using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.FactorizationMachine; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Trainers.FastTree; using Microsoft.ML.Runtime.Internal.Calibration; using Microsoft.ML.Runtime.Internal.Internallearn; -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime.Learners; using Microsoft.ML.Runtime.LightGBM; using Microsoft.ML.Runtime.RunTests; diff --git a/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs b/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs index 867c1ff476..21d468d90d 100644 --- a/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs +++ b/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs @@ -2,12 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.Ensemble; using Microsoft.ML.Runtime.Learners; using Microsoft.ML.Trainers.FastTree; -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; diff --git a/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs b/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs index 30fb77cf62..a35db114c0 100644 --- a/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs +++ b/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs @@ -3,10 +3,10 @@ // See the LICENSE file in the project root for more information. using Microsoft.ML.Core.Data; +using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.RunTests; using Microsoft.ML.Trainers; -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; using Microsoft.ML.Transforms.Text; From 58aa330f9469c8cb2d2ce5f9480e9b9a22f100d4 Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 27 Nov 2018 16:05:55 -0800 Subject: [PATCH 05/12] Making FastTree best friends with LightGBM --- src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs b/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs index a03d7bdab6..a916b9e406 100644 --- a/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs +++ b/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs @@ -6,5 +6,6 @@ using Microsoft.ML; [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Core.Tests" + PublicKey.TestValue)] +[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.LightGBM" + PublicKey.TestValue)] [assembly: WantsToBeBestFriends] From f8663e82e11962fe994425050ed41549d3b0ebfe Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 27 Nov 2018 17:07:40 -0800 Subject: [PATCH 06/12] Update core_ep-list.tsv --- src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs | 2 +- test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs b/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs index a916b9e406..cd27563c10 100644 --- a/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs +++ b/src/Microsoft.ML.FastTree/Properties/AssemblyInfo.cs @@ -6,6 +6,6 @@ using Microsoft.ML; [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Core.Tests" + PublicKey.TestValue)] -[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.LightGBM" + PublicKey.TestValue)] +[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.LightGBM" + PublicKey.Value)] [assembly: WantsToBeBestFriends] diff --git a/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv b/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv index 655b617d72..28a2ced558 100644 --- a/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv +++ b/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv @@ -57,7 +57,7 @@ Trainers.FastTreeTweedieRegressor Trains gradient boosted decision trees to fit Trainers.FieldAwareFactorizationMachineBinaryClassifier Train a field-aware factorization machine for binary classification Microsoft.ML.Runtime.FactorizationMachine.FieldAwareFactorizationMachineTrainer TrainBinary Microsoft.ML.Runtime.FactorizationMachine.FieldAwareFactorizationMachineTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput Trainers.GeneralizedAdditiveModelBinaryClassifier Trains a gradient boosted stump per feature, on all features simultaneously, to fit target values using least-squares. It mantains no interactions between features. Microsoft.ML.Trainers.FastTree.Gam TrainBinary Microsoft.ML.Trainers.FastTree.BinaryClassificationGamTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput Trainers.GeneralizedAdditiveModelRegressor Trains a gradient boosted stump per feature, on all features simultaneously, to fit target values using least-squares. It mantains no interactions between features. Microsoft.ML.Trainers.FastTree.Gam TrainRegression Microsoft.ML.Trainers.FastTree.RegressionGamTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RegressionOutput -Trainers.KMeansPlusPlusClusterer K-means is a popular clustering algorithm. With K-means, the data is clustered into a specified number of clusters in order to minimize the within-cluster sum of squares. K-means++ improves upon K-means by using a better method for choosing the initial cluster centers. Microsoft.ML.Trainers.KMeans.KMeansPlusPlusTrainer TrainKMeans Microsoft.ML.Trainers.KMeans.KMeansPlusPlusTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+ClusteringOutput +Trainers.KMeansPlusPlusClusterer K-means is a popular clustering algorithm. With K-means, the data is clustered into a specified number of clusters in order to minimize the within-cluster sum of squares. K-means++ improves upon K-means by using a better method for choosing the initial cluster centers. Microsoft.ML.KMeansClustering.KMeansPlusPlusTrainer TrainKMeans Microsoft.ML.KMeansClustering.KMeansPlusPlusTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+ClusteringOutput Trainers.LightGbmBinaryClassifier Train a LightGBM binary classification model. Microsoft.ML.Runtime.LightGBM.LightGbm TrainBinary Microsoft.ML.Runtime.LightGBM.LightGbmArguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput Trainers.LightGbmClassifier Train a LightGBM multi class model. Microsoft.ML.Runtime.LightGBM.LightGbm TrainMultiClass Microsoft.ML.Runtime.LightGBM.LightGbmArguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+MulticlassClassificationOutput Trainers.LightGbmRanker Train a LightGBM ranking model. Microsoft.ML.Runtime.LightGBM.LightGbm TrainRanking Microsoft.ML.Runtime.LightGBM.LightGbmArguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RankingOutput From 073ff0348f3d1acef1ade55a85902f26985b71fd Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 27 Nov 2018 17:37:33 -0800 Subject: [PATCH 07/12] Reverting libmf commit id --- src/Native/MatrixFactorizationNative/libmf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Native/MatrixFactorizationNative/libmf b/src/Native/MatrixFactorizationNative/libmf index 1ecc365249..f92a18161b 160000 --- a/src/Native/MatrixFactorizationNative/libmf +++ b/src/Native/MatrixFactorizationNative/libmf @@ -1 +1 @@ -Subproject commit 1ecc365249e5cac5e72c66317a141298dc52f6e3 +Subproject commit f92a18161b6824fda4c4ab698a69d299a836841a From 68def92da56ec7e216a7f6180bc1d05800af91d3 Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Mon, 3 Dec 2018 16:31:00 -0800 Subject: [PATCH 08/12] Explicitly implementing IValueMapper and ICanSaveInTextFormat everywhere --- .../Prediction/Calibrator.cs | 2 +- .../Trainer/EnsemblePredictorBase.cs | 2 +- src/Microsoft.ML.FastTree/FastTree.cs | 14 ++++++++---- src/Microsoft.ML.FastTree/GamTrainer.cs | 12 +++++----- src/Microsoft.ML.PCA/PcaTrainer.cs | 6 ++--- .../MatrixFactorizationPredictor.cs | 2 +- .../Standard/LinearPredictor.cs | 18 ++++++++++----- .../MulticlassLogisticRegression.cs | 9 +++++--- .../MultiClass/MultiClassNaiveBayesTrainer.cs | 6 ++--- .../Standard/MultiClass/Ova.cs | 22 +++++++++++++------ .../Standard/MultiClass/Pkpd.cs | 20 +++++++++-------- .../Training.cs | 2 +- 12 files changed, 72 insertions(+), 43 deletions(-) diff --git a/src/Microsoft.ML.Data/Prediction/Calibrator.cs b/src/Microsoft.ML.Data/Prediction/Calibrator.cs index 26ae54bd0b..bff0f79442 100644 --- a/src/Microsoft.ML.Data/Prediction/Calibrator.cs +++ b/src/Microsoft.ML.Data/Prediction/Calibrator.cs @@ -159,7 +159,7 @@ public void SaveAsIni(TextWriter writer, RoleMappedSchema schema, ICalibrator ca saver?.SaveAsIni(writer, schema, Calibrator); } - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { // REVIEW: What about the calibrator? var saver = SubPredictor as ICanSaveInTextFormat; diff --git a/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs b/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs index 1cedd9ec1c..72a81b12e3 100644 --- a/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs +++ b/src/Microsoft.ML.Ensemble/Trainer/EnsemblePredictorBase.cs @@ -128,7 +128,7 @@ private protected override void SaveCore(ModelSaveContext ctx) /// /// Output the INI model to a given writer /// - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { using (var ch = Host.Start("SaveAsText")) { diff --git a/src/Microsoft.ML.FastTree/FastTree.cs b/src/Microsoft.ML.FastTree/FastTree.cs index 1a492ff0bf..9cc6e1666c 100644 --- a/src/Microsoft.ML.FastTree/FastTree.cs +++ b/src/Microsoft.ML.FastTree/FastTree.cs @@ -2829,8 +2829,12 @@ public abstract class FastTreePredictionWrapper : protected abstract uint VerCategoricalSplitSerialized { get; } - public ColumnType InputType { get; } - public ColumnType OutputType => NumberType.Float; + protected internal readonly ColumnType InputType; + ColumnType IValueMapper.InputType => InputType; + + protected readonly ColumnType OutputType; + ColumnType IValueMapper.OutputType => OutputType; + bool ICanSavePfa.CanSavePfa => true; bool ICanSaveOnnx.CanSaveOnnx(OnnxContext ctx) => true; @@ -2852,6 +2856,7 @@ protected FastTreePredictionWrapper(IHostEnvironment env, string name, TreeEnsem Contracts.Assert(NumFeatures > MaxSplitFeatIdx); InputType = new VectorType(NumberType.Float, NumFeatures); + OutputType = NumberType.Float; } protected FastTreePredictionWrapper(IHostEnvironment env, string name, ModelLoadContext ctx, VersionInfo ver) @@ -2889,6 +2894,7 @@ protected FastTreePredictionWrapper(IHostEnvironment env, string name, ModelLoad // tricks. InputType = new VectorType(NumberType.Float, NumFeatures); + OutputType = NumberType.Float; } [BestFriend] @@ -2907,7 +2913,7 @@ private protected override void SaveCore(ModelSaveContext ctx) ctx.Writer.Write(NumFeatures); } - public ValueMapper GetMapper() + ValueMapper IValueMapper.GetMapper() { Host.Check(typeof(TIn) == typeof(VBuffer)); Host.Check(typeof(TOut) == typeof(Float)); @@ -2965,7 +2971,7 @@ public void SaveAsCode(TextWriter writer, RoleMappedSchema schema) /// /// Output the INI model to a given writer /// - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { Host.CheckValue(writer, nameof(writer)); Host.CheckValueOrNull(schema); diff --git a/src/Microsoft.ML.FastTree/GamTrainer.cs b/src/Microsoft.ML.FastTree/GamTrainer.cs index b38f64d381..8975e7423c 100644 --- a/src/Microsoft.ML.FastTree/GamTrainer.cs +++ b/src/Microsoft.ML.FastTree/GamTrainer.cs @@ -631,6 +631,7 @@ public abstract class GamPredictorBase : PredictorBase, public readonly double Intercept; private readonly int _numFeatures; private readonly ColumnType _inputType; + private readonly ColumnType _outputType; // These would be the bins for a totally sparse input. private readonly int[] _binsAtAllZero; // The output value for all zeros @@ -640,9 +641,8 @@ public abstract class GamPredictorBase : PredictorBase, private readonly int _inputLength; private readonly Dictionary _inputFeatureToDatasetFeatureMap; - public ColumnType InputType => _inputType; - - public ColumnType OutputType => NumberType.Float; + ColumnType IValueMapper.InputType => _inputType; + ColumnType IValueMapper.OutputType => _outputType; private protected GamPredictorBase(IHostEnvironment env, string name, int inputLength, Dataset trainSet, double meanEffect, double[][] binEffects, int[] featureMap) @@ -658,6 +658,7 @@ private protected GamPredictorBase(IHostEnvironment env, string name, _numFeatures = binEffects.Length; _inputType = new VectorType(NumberType.Float, _inputLength); + _outputType = NumberType.Float; _featureMap = featureMap; Intercept = meanEffect; @@ -762,6 +763,7 @@ protected GamPredictorBase(IHostEnvironment env, string name, ModelLoadContext c } _inputType = new VectorType(NumberType.Float, _inputLength); + _outputType = NumberType.Float; } public override void Save(ModelSaveContext ctx) @@ -1097,7 +1099,7 @@ private sealed class Context /// These are the number of input features, as opposed to the number of features used within GAM /// which may be lower. /// - public int NumFeatures => _pred.InputType.VectorSize; + public int NumFeatures => _pred._inputType.VectorSize; public Context(IChannel ch, GamPredictorBase pred, RoleMappedData data, IEvaluator eval) { @@ -1317,7 +1319,7 @@ private FeatureInfo(Context context, int index, int internalIndex, int[] catsMap public static FeatureInfo GetInfoForIndex(Context context, int index) { Contracts.AssertValue(context); - Contracts.Assert(0 <= index && index < context._pred.InputType.ValueCount); + Contracts.Assert(0 <= index && index < context._pred._inputType.ValueCount); lock (context._pred) { int internalIndex; diff --git a/src/Microsoft.ML.PCA/PcaTrainer.cs b/src/Microsoft.ML.PCA/PcaTrainer.cs index 8598fce92c..692ca15fb7 100644 --- a/src/Microsoft.ML.PCA/PcaTrainer.cs +++ b/src/Microsoft.ML.PCA/PcaTrainer.cs @@ -550,17 +550,17 @@ public IDataView GetSummaryDataView(RoleMappedSchema schema) return bldr.GetDataView(); } - public ColumnType InputType + ColumnType IValueMapper.InputType { get { return _inputType; } } - public ColumnType OutputType + ColumnType IValueMapper.OutputType { get { return NumberType.Float; } } - public ValueMapper GetMapper() + ValueMapper IValueMapper.GetMapper() { Host.Check(typeof(TIn) == typeof(VBuffer)); Host.Check(typeof(TOut) == typeof(float)); diff --git a/src/Microsoft.ML.Recommender/MatrixFactorizationPredictor.cs b/src/Microsoft.ML.Recommender/MatrixFactorizationPredictor.cs index 71219ee19e..f9c39fa88c 100644 --- a/src/Microsoft.ML.Recommender/MatrixFactorizationPredictor.cs +++ b/src/Microsoft.ML.Recommender/MatrixFactorizationPredictor.cs @@ -163,7 +163,7 @@ public void Save(ModelSaveContext ctx) /// /// Save the trained matrix factorization model (two factor matrices) in text format /// - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { writer.WriteLine("# Imputed matrix is P * Q'"); writer.WriteLine("# P in R^({0} x {1}), rows correpond to Y item", _numberOfRows, _approximationRank); diff --git a/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs b/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs index 01c53890ad..6f4ec3ebd1 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs @@ -97,9 +97,7 @@ IEnumerator IEnumerable.GetEnumerator() /// The predictor's bias term. public Float Bias { get; protected set; } - public ColumnType InputType { get; } - - public ColumnType OutputType => NumberType.Float; + private readonly ColumnType _inputType; bool ICanSavePfa.CanSavePfa => true; @@ -121,7 +119,7 @@ internal LinearPredictor(IHostEnvironment env, string name, in VBuffer we Weight = weights; Bias = bias; - InputType = new VectorType(NumberType.Float, Weight.Length); + _inputType = new VectorType(NumberType.Float, Weight.Length); if (Weight.IsDense) _weightsDense = Weight; @@ -176,7 +174,7 @@ protected LinearPredictor(IHostEnvironment env, string name, ModelLoadContext ct else Weight = new VBuffer(len, Utils.Size(weights), weights, indices); - InputType = new VectorType(NumberType.Float, Weight.Length); + _inputType = new VectorType(NumberType.Float, Weight.Length); WarnOnOldNormalizer(ctx, GetType(), Host); if (Weight.IsDense) @@ -284,6 +282,16 @@ private void EnsureWeightsDense() } } + ColumnType IValueMapper.InputType + { + get { return _inputType; } + } + + ColumnType IValueMapper.OutputType + { + get { return NumberType.Float; } + } + public ValueMapper GetMapper() { Contracts.Check(typeof(TIn) == typeof(VBuffer)); diff --git a/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs b/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs index 156abe3828..dffb2b4f82 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs @@ -394,8 +394,11 @@ private static VersionInfo GetVersionInfo() private volatile VBuffer[] _weightsDense; public override PredictionKind PredictionKind => PredictionKind.MultiClassClassification; - public ColumnType InputType { get; } - public ColumnType OutputType { get; } + internal readonly ColumnType InputType; + internal readonly ColumnType OutputType; + ColumnType IValueMapper.InputType => InputType; + ColumnType IValueMapper.OutputType => OutputType; + bool ICanSavePfa.CanSavePfa => true; bool ICanSaveOnnx.CanSaveOnnx(OnnxContext ctx) => true; @@ -710,7 +713,7 @@ private static int NonZeroCount(in VBuffer vector) return count; } - public ValueMapper GetMapper() + ValueMapper IValueMapper.GetMapper() { Host.Check(typeof(TSrc) == typeof(VBuffer), "Invalid source type in GetMapper"); Host.Check(typeof(TDst) == typeof(VBuffer), "Invalid destination type in GetMapper"); diff --git a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs index 8876e420aa..46e964a487 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/MultiClassNaiveBayesTrainer.cs @@ -209,9 +209,9 @@ private static VersionInfo GetVersionInfo() public override PredictionKind PredictionKind => PredictionKind.MultiClassClassification; - public ColumnType InputType => _inputType; + ColumnType IValueMapper.InputType => _inputType; - public ColumnType OutputType => _outputType; + ColumnType IValueMapper.OutputType => _outputType; /// /// Copies the label histogram into a buffer. @@ -352,7 +352,7 @@ private static double[] CalculateAbsentFeatureLogProbabilities(int[] labelHistog return absentFeaturesLogProb; } - public ValueMapper GetMapper() + ValueMapper IValueMapper.GetMapper() { Host.Check(typeof(TIn) == typeof(VBuffer)); Host.Check(typeof(TOut) == typeof(VBuffer)); diff --git a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs index a2263ab876..7f41ba7320 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Ova.cs @@ -226,9 +226,8 @@ private static VersionInfo GetVersionInfo() private readonly ImplBase _impl; public override PredictionKind PredictionKind => PredictionKind.MultiClassClassification; - public ColumnType InputType => _impl.InputType; - public ColumnType OutputType { get; } - public ColumnType DistType => OutputType; + private readonly ColumnType _outputType; + public ColumnType DistType => _outputType; bool ICanSavePfa.CanSavePfa => _impl.CanSavePfa; [BestFriend] @@ -279,7 +278,7 @@ private OvaPredictor(IHostEnvironment env, ImplBase impl) Host.Assert(Utils.Size(impl.Predictors) > 0); _impl = impl; - OutputType = new VectorType(NumberType.Float, _impl.Predictors.Length); + _outputType = new VectorType(NumberType.Float, _impl.Predictors.Length); } private OvaPredictor(IHostEnvironment env, ModelLoadContext ctx) @@ -305,7 +304,7 @@ private OvaPredictor(IHostEnvironment env, ModelLoadContext ctx) _impl = new ImplRaw(predictors); } - OutputType = new VectorType(NumberType.Float, _impl.Predictors.Length); + _outputType = new VectorType(NumberType.Float, _impl.Predictors.Length); } public static OvaPredictor Create(IHostEnvironment env, ModelLoadContext ctx) @@ -348,7 +347,16 @@ JToken ISingleCanSavePfa.SaveAsPfa(BoundPfaContext ctx, JToken input) return _impl.SaveAsPfa(ctx, input); } - public ValueMapper GetMapper() + ColumnType IValueMapper.InputType + { + get { return _impl.InputType; } + } + + ColumnType IValueMapper.OutputType + { + get { return _outputType; } + } + ValueMapper IValueMapper.GetMapper() { Host.Check(typeof(TIn) == typeof(VBuffer)); Host.Check(typeof(TOut) == typeof(VBuffer)); @@ -376,7 +384,7 @@ public void SaveAsCode(TextWriter writer, RoleMappedSchema schema) } } - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { Host.CheckValue(writer, nameof(writer)); Host.CheckValue(schema, nameof(schema)); diff --git a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs index 3d15fff849..e74d707d68 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/MultiClass/Pkpd.cs @@ -244,8 +244,10 @@ private static VersionInfo GetVersionInfo() private readonly IValueMapperDist[] _mappers; public override PredictionKind PredictionKind => PredictionKind.MultiClassClassification; - public ColumnType InputType { get; } - public ColumnType OutputType { get; } + private readonly ColumnType _inputType; + private readonly ColumnType _outputType; + ColumnType IValueMapper.InputType => _inputType; + ColumnType IValueMapper.OutputType => _outputType; internal PkpdPredictor(IHostEnvironment env, TDistPredictor[][] predictors) : base(env, RegistrationName) @@ -267,8 +269,8 @@ internal PkpdPredictor(IHostEnvironment env, TDistPredictor[][] predictors) : } Host.Assert(index == _predictors.Length); - InputType = InitializeMappers(out _mappers); - OutputType = new VectorType(NumberType.Float, _numClasses); + _inputType = InitializeMappers(out _mappers); + _outputType = new VectorType(NumberType.Float, _numClasses); } private PkpdPredictor(IHostEnvironment env, ModelLoadContext ctx) @@ -295,8 +297,8 @@ private PkpdPredictor(IHostEnvironment env, ModelLoadContext ctx) Host.Assert(index == GetIndex(i, i)); ctx.LoadModel(Host, out _predictors[index++], string.Format(SubPredictorFmt, i)); } - InputType = InitializeMappers(out _mappers); - OutputType = new VectorType(NumberType.Float, _numClasses); + _inputType = InitializeMappers(out _mappers); + _outputType = new VectorType(NumberType.Float, _numClasses); } private ColumnType InitializeMappers(out IValueMapperDist[] mappers) @@ -442,7 +444,7 @@ private int GetIndex(int i, int j) return i * (i + 1) / 2 + j; } - public ValueMapper GetMapper() + ValueMapper IValueMapper.GetMapper() { Host.Check(typeof(TIn) == typeof(VBuffer)); Host.Check(typeof(TOut) == typeof(VBuffer)); @@ -455,8 +457,8 @@ public ValueMapper GetMapper() ValueMapper, VBuffer> del = (in VBuffer src, ref VBuffer dst) => { - if (InputType.VectorSize > 0) - Host.Check(src.Length == InputType.VectorSize); + if (_inputType.VectorSize > 0) + Host.Check(src.Length == _inputType.VectorSize); var tmp = src; Parallel.For(0, maps.Length, i => diff --git a/test/Microsoft.ML.StaticPipelineTesting/Training.cs b/test/Microsoft.ML.StaticPipelineTesting/Training.cs index 4e485592e9..99ba150a49 100644 --- a/test/Microsoft.ML.StaticPipelineTesting/Training.cs +++ b/test/Microsoft.ML.StaticPipelineTesting/Training.cs @@ -14,12 +14,12 @@ using Microsoft.ML.Runtime.RunTests; using Microsoft.ML.StaticPipe; using Microsoft.ML.Trainers; +using Microsoft.ML.Trainers.Recommender; using Microsoft.ML.Transforms.Categorical; using System; using System.Linq; using Xunit; using Xunit.Abstractions; -using Microsoft.ML.Trainers.Recommender; namespace Microsoft.ML.StaticPipelineTesting { From a36eb9b7a45101a0aa5ab370e3453cc6ef8fd50c Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 4 Dec 2018 10:29:55 -0800 Subject: [PATCH 09/12] Final cleanup --- src/Microsoft.ML.FastTree/GamTrainer.cs | 4 ++-- src/Microsoft.ML.HalLearners/OlsLinearRegression.cs | 2 +- src/Microsoft.ML.PCA/PcaTrainer.cs | 4 ++-- src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs | 4 ++-- .../LogisticRegression/MulticlassLogisticRegression.cs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.ML.FastTree/GamTrainer.cs b/src/Microsoft.ML.FastTree/GamTrainer.cs index 8975e7423c..d073c40b5b 100644 --- a/src/Microsoft.ML.FastTree/GamTrainer.cs +++ b/src/Microsoft.ML.FastTree/GamTrainer.cs @@ -977,7 +977,7 @@ public double[] GetFeatureWeights(int featureIndex) return featureWeights; } - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { Host.CheckValue(writer, nameof(writer)); Host.CheckValueOrNull(schema); @@ -1020,7 +1020,7 @@ public void SaveAsText(TextWriter writer, RoleMappedSchema schema) public void SaveSummary(TextWriter writer, RoleMappedSchema schema) { - SaveAsText(writer, schema); + ((ICanSaveInTextFormat)this).SaveAsText(writer, schema); } /// diff --git a/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs b/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs index ffb061f6b7..0442118442 100644 --- a/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs +++ b/src/Microsoft.ML.HalLearners/OlsLinearRegression.cs @@ -296,7 +296,7 @@ private OlsLinearRegressionPredictor TrainCore(IChannel ch, FloatLabelCursor.Fac Double tss = 0; // total sum of squares using (var cursor = cursorFactory.Create()) { - var lrPredictor = new LinearRegressionPredictor(Host, in weights, bias); + IValueMapper lrPredictor = new LinearRegressionPredictor(Host, in weights, bias); var lrMap = lrPredictor.GetMapper, float>(); float yh = default; while (cursor.MoveNext()) diff --git a/src/Microsoft.ML.PCA/PcaTrainer.cs b/src/Microsoft.ML.PCA/PcaTrainer.cs index 692ca15fb7..6a48ce5d3f 100644 --- a/src/Microsoft.ML.PCA/PcaTrainer.cs +++ b/src/Microsoft.ML.PCA/PcaTrainer.cs @@ -500,10 +500,10 @@ public static PcaPredictor Create(IHostEnvironment env, ModelLoadContext ctx) public void SaveSummary(TextWriter writer, RoleMappedSchema schema) { - SaveAsText(writer, schema); + ((ICanSaveInTextFormat)this).SaveAsText(writer, schema); } - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { writer.WriteLine("Dimension: {0}", _dimension); writer.WriteLine("Rank: {0}", _rank); diff --git a/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs b/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs index 6f4ec3ebd1..be074d5866 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/LinearPredictor.cs @@ -292,7 +292,7 @@ ColumnType IValueMapper.OutputType get { return NumberType.Float; } } - public ValueMapper GetMapper() + ValueMapper IValueMapper.GetMapper() { Contracts.Check(typeof(TIn) == typeof(VBuffer)); Contracts.Check(typeof(TOut) == typeof(Float)); @@ -335,7 +335,7 @@ protected void CombineParameters(IList> models, out VBuff bias /= models.Count; } - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { Host.CheckValue(writer, nameof(writer)); Host.CheckValue(schema, nameof(schema)); diff --git a/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs b/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs index dffb2b4f82..d4bd1f73ae 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs @@ -784,7 +784,7 @@ private void Calibrate(Span dst) /// /// Output the text model to a given writer /// - public void SaveAsText(TextWriter writer, RoleMappedSchema schema) + void ICanSaveInTextFormat.SaveAsText(TextWriter writer, RoleMappedSchema schema) { writer.WriteLine(nameof(MulticlassLogisticRegression) + " bias and non-zero weights"); @@ -860,7 +860,7 @@ public void SaveAsCode(TextWriter writer, RoleMappedSchema schema) public void SaveSummary(TextWriter writer, RoleMappedSchema schema) { - SaveAsText(writer, schema); + ((ICanSaveInTextFormat)this).SaveAsText(writer, schema); } JToken ISingleCanSavePfa.SaveAsPfa(BoundPfaContext ctx, JToken input) From 5ca4465e1be688f32533d77a3e4607dc6a400418 Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 4 Dec 2018 15:03:06 -0800 Subject: [PATCH 10/12] addressing some comments --- docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs | 4 ++-- src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs index 809459d4b5..c25e75b0e2 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/KMeans.cs @@ -14,7 +14,7 @@ public static void KMeans() var ml = new MLContext(); // Get a small dataset as an IEnumerable and convert it to an IDataView. - IEnumerable data = SamplesUtils.DatasetUtils.GetInfertData(); + var data = SamplesUtils.DatasetUtils.GetInfertData(); var trainData = ml.CreateStreamingDataView(data); // Preview of the data. @@ -33,7 +33,7 @@ public static void KMeans() var model = pipeline.Fit(trainData); - // Get centroids and k from KMeansModelParameters. + // Get cluster centroids and the number of clusters k from KMeansModelParameters. VBuffer[] centroids = default; int k; diff --git a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs index 23b64dd4ba..aff5d770f7 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs @@ -21,6 +21,12 @@ namespace Microsoft.ML.KMeansClustering { + /// + /// + /// + /// public sealed class KMeansModelParameters : PredictorBase>, IValueMapper, From dbbfa643769956415467d74f510d329b6763f7c9 Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 4 Dec 2018 16:42:28 -0800 Subject: [PATCH 11/12] reverting namespace change --- src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs | 2 +- src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs | 4 ++-- src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs | 4 ++-- src/Microsoft.ML.KMeansClustering/KMeansStatic.cs | 2 +- src/Microsoft.ML.Legacy/AssemblyRegistration.cs | 2 +- test/Microsoft.ML.StaticPipelineTesting/Training.cs | 4 ++-- test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs | 2 +- .../Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs b/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs index 939ab92579..c096750ae0 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; +using Microsoft.ML.Trainers.KMeans; using System; namespace Microsoft.ML diff --git a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs index aff5d770f7..e5862249bb 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansModelParameters.cs @@ -4,7 +4,6 @@ using Float = System.Single; -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.Internal.Internallearn; @@ -12,6 +11,7 @@ using Microsoft.ML.Runtime.Model; using Microsoft.ML.Runtime.Model.Onnx; using Microsoft.ML.Runtime.Numeric; +using Microsoft.ML.Trainers.KMeans; using System; using System.IO; using System.Collections.Generic; @@ -19,7 +19,7 @@ [assembly: LoadableClass(typeof(KMeansModelParameters), null, typeof(SignatureLoadModel), "KMeans predictor", KMeansModelParameters.LoaderSignature)] -namespace Microsoft.ML.KMeansClustering +namespace Microsoft.ML.Trainers.KMeans { /// /// diff --git a/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs b/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs index 5f3de7b04a..a72d148be7 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs @@ -4,7 +4,6 @@ using Microsoft.ML.Core.Data; using Microsoft.ML.Data; -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.CommandLine; using Microsoft.ML.Runtime.Data; @@ -14,6 +13,7 @@ using Microsoft.ML.Runtime.Internal.Utilities; using Microsoft.ML.Runtime.Numeric; using Microsoft.ML.Runtime.Training; +using Microsoft.ML.Trainers.KMeans; using System; using System.Linq; using System.Threading.Tasks; @@ -26,7 +26,7 @@ [assembly: LoadableClass(typeof(void), typeof(KMeansPlusPlusTrainer), null, typeof(SignatureEntryPointModule), "KMeans")] -namespace Microsoft.ML.KMeansClustering +namespace Microsoft.ML.Trainers.KMeans { /// public class KMeansPlusPlusTrainer : TrainerEstimatorBase, KMeansModelParameters> diff --git a/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs b/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs index eb27c9fef2..1fb94afc8e 100644 --- a/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs +++ b/src/Microsoft.ML.KMeansClustering/KMeansStatic.cs @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; using Microsoft.ML.StaticPipe.Runtime; +using Microsoft.ML.Trainers.KMeans; using System; namespace Microsoft.ML.StaticPipe diff --git a/src/Microsoft.ML.Legacy/AssemblyRegistration.cs b/src/Microsoft.ML.Legacy/AssemblyRegistration.cs index 0c927b53b8..47ff917bf8 100644 --- a/src/Microsoft.ML.Legacy/AssemblyRegistration.cs +++ b/src/Microsoft.ML.Legacy/AssemblyRegistration.cs @@ -2,12 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime.Api; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.Sweeper; using Microsoft.ML.Runtime.Tools; using Microsoft.ML.Trainers.FastTree; +using Microsoft.ML.Trainers.KMeans; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; using System; diff --git a/test/Microsoft.ML.StaticPipelineTesting/Training.cs b/test/Microsoft.ML.StaticPipelineTesting/Training.cs index 99ba150a49..e1a5f7be3d 100644 --- a/test/Microsoft.ML.StaticPipelineTesting/Training.cs +++ b/test/Microsoft.ML.StaticPipelineTesting/Training.cs @@ -5,8 +5,6 @@ using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.FactorizationMachine; -using Microsoft.ML.KMeansClustering; -using Microsoft.ML.Trainers.FastTree; using Microsoft.ML.Runtime.Internal.Calibration; using Microsoft.ML.Runtime.Internal.Internallearn; using Microsoft.ML.Runtime.Learners; @@ -14,6 +12,8 @@ using Microsoft.ML.Runtime.RunTests; using Microsoft.ML.StaticPipe; using Microsoft.ML.Trainers; +using Microsoft.ML.Trainers.FastTree; +using Microsoft.ML.Trainers.KMeans; using Microsoft.ML.Trainers.Recommender; using Microsoft.ML.Transforms.Categorical; using System; diff --git a/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs b/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs index 21d468d90d..139baafeaf 100644 --- a/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs +++ b/test/Microsoft.ML.TestFramework/EnvironmentExtensions.cs @@ -2,12 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.Ensemble; using Microsoft.ML.Runtime.Learners; using Microsoft.ML.Trainers.FastTree; +using Microsoft.ML.Trainers.KMeans; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; diff --git a/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs b/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs index a35db114c0..1ac7c28622 100644 --- a/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs +++ b/test/Microsoft.ML.Tests/TrainerEstimators/TrainerEstimators.cs @@ -3,10 +3,10 @@ // See the LICENSE file in the project root for more information. using Microsoft.ML.Core.Data; -using Microsoft.ML.KMeansClustering; using Microsoft.ML.Runtime.Data; using Microsoft.ML.Runtime.RunTests; using Microsoft.ML.Trainers; +using Microsoft.ML.Trainers.KMeans; using Microsoft.ML.Trainers.PCA; using Microsoft.ML.Transforms.Categorical; using Microsoft.ML.Transforms.Text; From a31d811d43299759295c4c3ee1f92dcb5e7e8ce3 Mon Sep 17 00:00:00 2001 From: "REDMOND\\nakazmi" Date: Tue, 4 Dec 2018 16:47:24 -0800 Subject: [PATCH 12/12] update core_ep-list.tsv --- test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv b/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv index 28a2ced558..655b617d72 100644 --- a/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv +++ b/test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv @@ -57,7 +57,7 @@ Trainers.FastTreeTweedieRegressor Trains gradient boosted decision trees to fit Trainers.FieldAwareFactorizationMachineBinaryClassifier Train a field-aware factorization machine for binary classification Microsoft.ML.Runtime.FactorizationMachine.FieldAwareFactorizationMachineTrainer TrainBinary Microsoft.ML.Runtime.FactorizationMachine.FieldAwareFactorizationMachineTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput Trainers.GeneralizedAdditiveModelBinaryClassifier Trains a gradient boosted stump per feature, on all features simultaneously, to fit target values using least-squares. It mantains no interactions between features. Microsoft.ML.Trainers.FastTree.Gam TrainBinary Microsoft.ML.Trainers.FastTree.BinaryClassificationGamTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput Trainers.GeneralizedAdditiveModelRegressor Trains a gradient boosted stump per feature, on all features simultaneously, to fit target values using least-squares. It mantains no interactions between features. Microsoft.ML.Trainers.FastTree.Gam TrainRegression Microsoft.ML.Trainers.FastTree.RegressionGamTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RegressionOutput -Trainers.KMeansPlusPlusClusterer K-means is a popular clustering algorithm. With K-means, the data is clustered into a specified number of clusters in order to minimize the within-cluster sum of squares. K-means++ improves upon K-means by using a better method for choosing the initial cluster centers. Microsoft.ML.KMeansClustering.KMeansPlusPlusTrainer TrainKMeans Microsoft.ML.KMeansClustering.KMeansPlusPlusTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+ClusteringOutput +Trainers.KMeansPlusPlusClusterer K-means is a popular clustering algorithm. With K-means, the data is clustered into a specified number of clusters in order to minimize the within-cluster sum of squares. K-means++ improves upon K-means by using a better method for choosing the initial cluster centers. Microsoft.ML.Trainers.KMeans.KMeansPlusPlusTrainer TrainKMeans Microsoft.ML.Trainers.KMeans.KMeansPlusPlusTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+ClusteringOutput Trainers.LightGbmBinaryClassifier Train a LightGBM binary classification model. Microsoft.ML.Runtime.LightGBM.LightGbm TrainBinary Microsoft.ML.Runtime.LightGBM.LightGbmArguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput Trainers.LightGbmClassifier Train a LightGBM multi class model. Microsoft.ML.Runtime.LightGBM.LightGbm TrainMultiClass Microsoft.ML.Runtime.LightGBM.LightGbmArguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+MulticlassClassificationOutput Trainers.LightGbmRanker Train a LightGBM ranking model. Microsoft.ML.Runtime.LightGBM.LightGbm TrainRanking Microsoft.ML.Runtime.LightGBM.LightGbmArguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RankingOutput