private static SuggestedPipeline BuildSuggestedPipeline(SuggestedTrainer trainer, CacheBeforeTrainer cacheBeforeTrainer = CacheBeforeTrainer.Auto) { return(SuggestedPipelineBuilder.Build(_context, new List <SuggestedTransform>(), new List <SuggestedTransform>(), trainer, cacheBeforeTrainer)); }
private static void TestPipelineBuilderCaching( SuggestedTrainer trainer, CacheBeforeTrainer[] cacheBeforeTrainerSettings, bool[] resultShouldHaveCaching) { for (var i = 0; i < cacheBeforeTrainerSettings.Length; i++) { var suggestedPipeline = BuildSuggestedPipeline(trainer, cacheBeforeTrainerSettings[i]); Assert.Equal(resultShouldHaveCaching[i], suggestedPipeline.ToPipeline().CacheBeforeTrainer); } }
private (Pipeline, ColumnInferenceResults) GetMockedOvaPipelineAndInference() { if (_mockedOvaPipeline == null) { MLContext context = new MLContext(); // same learners with different hyperparameters var hyperparams1 = new Microsoft.ML.AutoML.ParameterSet(new List <Microsoft.ML.AutoML.IParameterValue>() { new LongParameterValue("NumLeaves", 2) }); var trainer1 = new SuggestedTrainer(context, new FastForestOvaExtension(), new ColumnInformation(), hyperparams1); var transforms1 = new List <SuggestedTransform>() { ColumnConcatenatingExtension.CreateSuggestedTransform(context, new[] { "In" }, "Out") }; var inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, true); this._mockedOvaPipeline = inferredPipeline1.ToPipeline(); var textLoaderArgs = new TextLoader.Options() { Columns = new[] { new TextLoader.Column("Label", DataKind.Boolean, 0), new TextLoader.Column("col1", DataKind.Single, 1), new TextLoader.Column("col2", DataKind.Single, 0), new TextLoader.Column("col3", DataKind.String, 0), new TextLoader.Column("col4", DataKind.Int32, 0), new TextLoader.Column("col5", DataKind.UInt32, 0), }, AllowQuoting = true, AllowSparse = true, HasHeader = true, Separators = new[] { ',' } }; this._columnInference = new ColumnInferenceResults() { TextLoaderOptions = textLoaderArgs, ColumnInformation = new ColumnInformation() { LabelColumnName = "Label" } }; } return(_mockedOvaPipeline, _columnInference); }
private (Pipeline, ColumnInferenceResults) GetMockedRecommendationPipelineAndInference() { if (mockedPipeline == null) { MLContext context = new MLContext(); var trainer1 = new SuggestedTrainer(context, new MatrixFactorizationExtension(), new ColumnInformation() { LabelColumnName = "Label", UserIdColumnName = "userId", ItemIdColumnName = "movieId", }, hyperParamSet: null); var transforms1 = new List <SuggestedTransform>() { ColumnConcatenatingExtension.CreateSuggestedTransform(context, new[] { "In" }, "Out") }; var inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, false); mockedPipeline = inferredPipeline1.ToPipeline(); var textLoaderArgs = new TextLoader.Options() { Columns = new[] { new TextLoader.Column("Label", DataKind.String, 0), new TextLoader.Column("userId", DataKind.String, 1), new TextLoader.Column("movieId", DataKind.String, 2), }, AllowQuoting = true, AllowSparse = true, HasHeader = true, Separators = new[] { ',' } }; this.columnInference = new ColumnInferenceResults() { TextLoaderOptions = textLoaderArgs, ColumnInformation = new ColumnInformation() { LabelColumnName = "Label", UserIdColumnName = "userId", ItemIdColumnName = "movieId" } }; } return(mockedPipeline, columnInference); }
public void InferredPipelinesHashTest() { var context = new MLContext(); var columnInfo = new ColumnInformation(); // test same learners with no hyperparams have the same hash code var trainer1 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo); var trainer2 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo); var transforms1 = new List <SuggestedTransform>(); var transforms2 = new List <SuggestedTransform>(); var inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, false); var inferredPipeline2 = new SuggestedPipeline(transforms2, new List <SuggestedTransform>(), trainer2, context, false); Assert.Equal(inferredPipeline1.GetHashCode(), inferredPipeline2.GetHashCode()); // test same learners with hyperparams set vs empty hyperparams have different hash codes var hyperparams1 = new ParameterSet(new List <IParameterValue>() { new LongParameterValue("NumberOfLeaves", 2) }); trainer1 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo, hyperparams1); trainer2 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo); inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, false); inferredPipeline2 = new SuggestedPipeline(transforms2, new List <SuggestedTransform>(), trainer2, context, false); Assert.NotEqual(inferredPipeline1.GetHashCode(), inferredPipeline2.GetHashCode()); // same learners with different hyperparams hyperparams1 = new ParameterSet(new List <IParameterValue>() { new LongParameterValue("NumberOfLeaves", 2) }); var hyperparams2 = new ParameterSet(new List <IParameterValue>() { new LongParameterValue("NumberOfLeaves", 6) }); trainer1 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo, hyperparams1); trainer2 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo, hyperparams2); inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, false); inferredPipeline2 = new SuggestedPipeline(transforms2, new List <SuggestedTransform>(), trainer2, context, false); Assert.NotEqual(inferredPipeline1.GetHashCode(), inferredPipeline2.GetHashCode()); // same learners with same transforms trainer1 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo); trainer2 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo); transforms1 = new List <SuggestedTransform>() { ColumnConcatenatingExtension.CreateSuggestedTransform(context, new[] { "In" }, "Out") }; transforms2 = new List <SuggestedTransform>() { ColumnConcatenatingExtension.CreateSuggestedTransform(context, new[] { "In" }, "Out") }; inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, false); inferredPipeline2 = new SuggestedPipeline(transforms2, new List <SuggestedTransform>(), trainer2, context, false); Assert.Equal(inferredPipeline1.GetHashCode(), inferredPipeline2.GetHashCode()); // same transforms with different learners trainer1 = new SuggestedTrainer(context, new SdcaLogisticRegressionBinaryExtension(), columnInfo); trainer2 = new SuggestedTrainer(context, new LightGbmBinaryExtension(), columnInfo); transforms1 = new List <SuggestedTransform>() { ColumnConcatenatingExtension.CreateSuggestedTransform(context, new[] { "In" }, "Out") }; transforms2 = new List <SuggestedTransform>() { ColumnConcatenatingExtension.CreateSuggestedTransform(context, new[] { "In" }, "Out") }; inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, false); inferredPipeline2 = new SuggestedPipeline(transforms2, new List <SuggestedTransform>(), trainer2, context, false); Assert.NotEqual(inferredPipeline1.GetHashCode(), inferredPipeline2.GetHashCode()); }