예제 #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="FastTreeBinaryClassificationTrainer"/>
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="weightColumn">The name for the column containing the initial weight.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        /// <param name="learningRate">The learning rate.</param>
        /// <param name="minDocumentsInLeafs">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
        /// <param name="numLeaves">The max number of leaves in each regression tree.</param>
        /// <param name="numTrees">Total number of decision trees to create in the ensemble.</param>
        public FastTreeBinaryClassificationTrainer(IHostEnvironment env,
                                                   string labelColumn,
                                                   string featureColumn,
                                                   string weightColumn                 = null,
                                                   int numLeaves                       = Defaults.NumLeaves,
                                                   int numTrees                        = Defaults.NumTrees,
                                                   int minDocumentsInLeafs             = Defaults.MinDocumentsInLeafs,
                                                   double learningRate                 = Defaults.LearningRates,
                                                   Action <Arguments> advancedSettings = null)
            : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, advancedSettings)
        {
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));

            // Set the sigmoid parameter to the 2 * learning rate, for traditional FastTreeClassification loss
            _sigmoidParameter = 2.0 * Args.LearningRates;

            if (advancedSettings != null)
            {
                CheckArgsAndAdvancedSettingMismatch(numLeaves, numTrees, minDocumentsInLeafs, learningRate, new Arguments(), Args);
            }

            //override with the directly provided values.
            Args.NumLeaves           = numLeaves;
            Args.NumTrees            = numTrees;
            Args.MinDocumentsInLeafs = minDocumentsInLeafs;
            Args.LearningRates       = learningRate;
        }
예제 #2
0
        protected CalibratorEstimatorBase(IHostEnvironment env,
                                          TCalibratorTrainer calibratorTrainer,
                                          IPredictor predictor = null,
                                          string labelColumn   = DefaultColumnNames.Label,
                                          string featureColumn = DefaultColumnNames.Features,
                                          string weightColumn  = null)
        {
            Host              = env;
            Predictor         = predictor;
            CalibratorTrainer = calibratorTrainer;

            ScoreColumn    = TrainerUtils.MakeR4ScalarColumn(DefaultColumnNames.Score); // Do we fantom this being named anything else (renaming column)? Complete metadata?
            LabelColumn    = TrainerUtils.MakeBoolScalarLabel(labelColumn);
            FeatureColumn  = TrainerUtils.MakeR4VecFeature(featureColumn);
            PredictedLabel = new SchemaShape.Column(DefaultColumnNames.PredictedLabel,
                                                    SchemaShape.Column.VectorKind.Scalar,
                                                    BoolType.Instance,
                                                    false,
                                                    new SchemaShape(MetadataUtils.GetTrainerOutputMetadata()));

            if (weightColumn != null)
            {
                WeightColumn = TrainerUtils.MakeR4ScalarWeightColumn(weightColumn);
            }
        }
 /// <summary>
 /// Initializes a new instance of <see cref="FastForestClassification"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="groupIdColumn">The name for the column containing the group ID.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
 public FastForestClassification(IHostEnvironment env, string labelColumn, string featureColumn,
                                 string groupIdColumn = null, string weightColumn = null, Action <Arguments> advancedSettings = null)
     : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, groupIdColumn, advancedSettings: advancedSettings)
 {
     Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
     Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of <see cref="LightGbmBinaryTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="groupIdColumn">The name for the column containing the group ID. </param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
 public LightGbmBinaryTrainer(IHostEnvironment env, string labelColumn, string featureColumn,
                              string groupIdColumn = null, string weightColumn = null, Action <LightGbmArguments> advancedSettings = null)
     : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, groupIdColumn, advancedSettings)
 {
     Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
     Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
 }
 /// <summary>
 /// Initializes a new instance of <see cref="SymSgdClassificationTrainer"/>
 /// </summary>
 internal SymSgdClassificationTrainer(IHostEnvironment env, Arguments args)
     : base(Contracts.CheckRef(env, nameof(env)).Register(LoadNameValue), TrainerUtils.MakeR4VecFeature(args.FeatureColumn),
            TrainerUtils.MakeBoolScalarLabel(args.LabelColumn))
 {
     args.Check(Host);
     _args = args;
     Info  = new TrainerInfo();
 }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of <see cref="BinaryClassificationGamTrainer"/>
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="weightColumn">The name for the column containing the initial weight.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        public BinaryClassificationGamTrainer(IHostEnvironment env, string labelColumn, string featureColumn, string weightColumn = null, Action <Arguments> advancedSettings = null)
            : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, advancedSettings)
        {
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));

            _sigmoidParameter = 1;
        }
 /// <summary>
 /// Initializes a new instance of <see cref="LightGbmBinaryTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="numLeaves">The number of leaves to use.</param>
 /// <param name="numBoostRound">Number of iterations.</param>
 /// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="advancedSettings">A delegate to set more settings.
 /// The settings here will override the ones provided in the direct signature,
 /// if both are present and have different values.
 /// The columns names, however need to be provided directly, not through the <paramref name="advancedSettings"/>.</param>
 public LightGbmBinaryTrainer(IHostEnvironment env, string labelColumn, string featureColumn,
                              string weightColumn = null,
                              int?numLeaves       = null,
                              int?minDataPerLeaf  = null,
                              double?learningRate = null,
                              int numBoostRound   = LightGbmArguments.Defaults.NumBoostRound,
                              Action <LightGbmArguments> advancedSettings = null)
     : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, numLeaves, minDataPerLeaf, learningRate, numBoostRound, advancedSettings)
 {
 }
        /// <summary>
        /// Initializes a new instance of <see cref="FastTreeBinaryClassificationTrainer"/>
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="groupIdColumn">The name for the column containing the group ID. </param>
        /// <param name="weightColumn">The name for the column containing the initial weight.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        public FastTreeBinaryClassificationTrainer(IHostEnvironment env, string labelColumn, string featureColumn,
                                                   string groupIdColumn = null, string weightColumn = null, Action <Arguments> advancedSettings = null)
            : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, groupIdColumn, advancedSettings)
        {
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));

            // Set the sigmoid parameter to the 2 * learning rate, for traditional FastTreeClassification loss
            _sigmoidParameter = 2.0 * Args.LearningRates;
        }
        /// <summary>
        /// Initializes a new instance of <see cref="SymSgdClassificationTrainer"/>
        /// </summary>
        internal SymSgdClassificationTrainer(IHostEnvironment env, Options options)
            : base(Contracts.CheckRef(env, nameof(env)).Register(LoadNameValue), TrainerUtils.MakeR4VecFeature(options.FeatureColumn),
                   TrainerUtils.MakeBoolScalarLabel(options.LabelColumn))
        {
            Host.CheckValue(options, nameof(options));
            options.Check(Host);

            _options = options;
            Info     = new TrainerInfo(supportIncrementalTrain: true);
        }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of <see cref="LightGbmBinaryClassificationTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumnName">The name of The label column.</param>
 /// <param name="featureColumnName">The name of the feature column.</param>
 /// <param name="exampleWeightColumnName">The name of the example weight column (optional).</param>
 /// <param name="numberOfLeaves">The number of leaves to use.</param>
 /// <param name="minimumExampleCountPerLeaf">The minimal number of data points allowed in a leaf of the tree, out of the subsampled data.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="numberOfIterations">Number of iterations.</param>
 internal LightGbmBinaryClassificationTrainer(IHostEnvironment env,
                                              string labelColumnName         = DefaultColumnNames.Label,
                                              string featureColumnName       = DefaultColumnNames.Features,
                                              string exampleWeightColumnName = null,
                                              int?numberOfLeaves             = null,
                                              int?minimumExampleCountPerLeaf = null,
                                              double?learningRate            = null,
                                              int numberOfIterations         = Trainers.LightGbm.Options.Defaults.NumberOfIterations)
     : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumnName), featureColumnName, exampleWeightColumnName, null, numberOfLeaves, minimumExampleCountPerLeaf, learningRate, numberOfIterations)
 {
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of <see cref="BinaryClassificationGamTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="minDatapointsInLeaves">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
 /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
 public BinaryClassificationGamTrainer(IHostEnvironment env,
                                       string labelColumn                  = DefaultColumnNames.Label,
                                       string featureColumn                = DefaultColumnNames.Features,
                                       string weightColumn                 = null,
                                       int minDatapointsInLeaves           = Defaults.MinDocumentsInLeaves,
                                       double learningRate                 = Defaults.LearningRates,
                                       Action <Arguments> advancedSettings = null)
     : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, minDatapointsInLeaves, learningRate, advancedSettings)
 {
     _sigmoidParameter = 1;
 }
예제 #12
0
        /// <summary>
        /// Initializes a new instance of <see cref="LogisticRegression"/>
        /// </summary>
        internal LogisticRegression(IHostEnvironment env, Arguments args)
            : base(env, args, TrainerUtils.MakeBoolScalarLabel(args.LabelColumn))
        {
            _posWeight        = 0;
            ShowTrainingStats = Args.ShowTrainingStats;

            if (ShowTrainingStats && Args.StdComputer == null)
            {
                Args.StdComputer = new ComputeLRTrainingStdImpl();
            }
        }
 /// <summary>
 /// Initializes a new instance of <see cref="BinaryClassificationGamTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="numIterations">The number of iterations to use in learning the features.</param>
 /// <param name="learningRate">The learning rate. GAMs work best with a small learning rate.</param>
 /// <param name="maxBins">The maximum number of bins to use to approximate features</param>
 internal BinaryClassificationGamTrainer(IHostEnvironment env,
                                         string labelColumn   = DefaultColumnNames.Label,
                                         string featureColumn = DefaultColumnNames.Features,
                                         string weightColumn  = null,
                                         int numIterations    = GamDefaults.NumIterations,
                                         double learningRate  = GamDefaults.LearningRates,
                                         int maxBins          = GamDefaults.MaxBins)
     : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, numIterations, learningRate, maxBins)
 {
     _sigmoidParameter = 1;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="GamBinaryTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumnName">The name of the label column.</param>
 /// <param name="featureColumnName">The name of the feature column.</param>
 /// <param name="rowGroupColumnName">The name for the column containing the example weight.</param>
 /// <param name="numberOfIterations">The number of iterations to use in learning the features.</param>
 /// <param name="learningRate">The learning rate. GAMs work best with a small learning rate.</param>
 /// <param name="maximumBinCountPerFeature">The maximum number of bins to use to approximate features</param>
 internal GamBinaryTrainer(IHostEnvironment env,
                           string labelColumnName        = DefaultColumnNames.Label,
                           string featureColumnName      = DefaultColumnNames.Features,
                           string rowGroupColumnName     = null,
                           int numberOfIterations        = GamDefaults.NumberOfIterations,
                           double learningRate           = GamDefaults.LearningRate,
                           int maximumBinCountPerFeature = GamDefaults.MaximumBinCountPerFeature)
     : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumnName), featureColumnName, rowGroupColumnName, numberOfIterations, learningRate, maximumBinCountPerFeature)
 {
     _sigmoidParameter = 1;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="LightGbmBinaryTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of The label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weights">The name for the column containing the initial weight.</param>
 /// <param name="numLeaves">The number of leaves to use.</param>
 /// <param name="numBoostRound">Number of iterations.</param>
 /// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
 /// <param name="learningRate">The learning rate.</param>
 internal LightGbmBinaryTrainer(IHostEnvironment env,
                                string labelColumn   = DefaultColumnNames.Label,
                                string featureColumn = DefaultColumnNames.Features,
                                string weights       = null,
                                int?numLeaves        = null,
                                int?minDataPerLeaf   = null,
                                double?learningRate  = null,
                                int numBoostRound    = LightGBM.Options.Defaults.NumBoostRound)
     : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weights, null, numLeaves, minDataPerLeaf, learningRate, numBoostRound)
 {
 }
 /// <summary>
 /// Initializes a new instance of <see cref="FastForestClassification"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="numLeaves">The max number of leaves in each regression tree.</param>
 /// <param name="numTrees">Total number of decision trees to create in the ensemble.</param>
 /// <param name="minDatapointsInLeaves">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
 internal FastForestClassification(IHostEnvironment env,
                                   string labelColumn        = DefaultColumnNames.Label,
                                   string featureColumn      = DefaultColumnNames.Features,
                                   string weightColumn       = null,
                                   int numLeaves             = Defaults.NumLeaves,
                                   int numTrees              = Defaults.NumTrees,
                                   int minDatapointsInLeaves = Defaults.MinDocumentsInLeaves)
     : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, numLeaves, numTrees, minDatapointsInLeaves)
 {
     Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
     Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of <see cref="FastForestBinaryTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumnName">The name of the label column.</param>
 /// <param name="featureColumnName">The name of the feature column.</param>
 /// <param name="exampleWeightColumnName">The name for the column containing the example weight.</param>
 /// <param name="numberOfLeaves">The max number of leaves in each regression tree.</param>
 /// <param name="numberOfTrees">Total number of decision trees to create in the ensemble.</param>
 /// <param name="minimumExampleCountPerLeaf">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
 internal FastForestBinaryTrainer(IHostEnvironment env,
                                  string labelColumnName         = DefaultColumnNames.Label,
                                  string featureColumnName       = DefaultColumnNames.Features,
                                  string exampleWeightColumnName = null,
                                  int numberOfLeaves             = Defaults.NumberOfLeaves,
                                  int numberOfTrees = Defaults.NumberOfTrees,
                                  int minimumExampleCountPerLeaf = Defaults.MinimumExampleCountPerLeaf)
     : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumnName), featureColumnName, exampleWeightColumnName, null, numberOfLeaves, numberOfTrees, minimumExampleCountPerLeaf)
 {
     Host.CheckNonEmpty(labelColumnName, nameof(labelColumnName));
     Host.CheckNonEmpty(featureColumnName, nameof(featureColumnName));
 }
예제 #18
0
        public AveragedPerceptronTrainer(IHostEnvironment env, Arguments args)
            : base(args, env, UserNameValue, TrainerUtils.MakeBoolScalarLabel(args.LabelColumn))
        {
            _args        = args;
            LossFunction = _args.LossFunction.CreateComponent(env);

            _outputColumns = new[]
            {
                new SchemaShape.Column(DefaultColumnNames.Score, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false, new SchemaShape(MetadataUtils.GetTrainerOutputMetadata())),
                new SchemaShape.Column(DefaultColumnNames.Probability, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false, new SchemaShape(MetadataUtils.GetTrainerOutputMetadata(true))),
                new SchemaShape.Column(DefaultColumnNames.PredictedLabel, SchemaShape.Column.VectorKind.Scalar, BoolType.Instance, false, new SchemaShape(MetadataUtils.GetTrainerOutputMetadata()))
            };
        }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of <see cref="FastTreeBinaryTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumnName">The name of the label column.</param>
 /// <param name="featureColumnName">The name of the feature column.</param>
 /// <param name="exampleWeightColumnName">The name for the column containing the example weight.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="minimumExampleCountPerLeaf">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
 /// <param name="numberOfLeaves">The max number of leaves in each regression tree.</param>
 /// <param name="numberOfTrees">Total number of decision trees to create in the ensemble.</param>
 internal FastTreeBinaryTrainer(IHostEnvironment env,
                                string labelColumnName         = DefaultColumnNames.Label,
                                string featureColumnName       = DefaultColumnNames.Features,
                                string exampleWeightColumnName = null,
                                int numberOfLeaves             = Defaults.NumberOfLeaves,
                                int numberOfTrees = Defaults.NumberOfTrees,
                                int minimumExampleCountPerLeaf = Defaults.MinimumExampleCountPerLeaf,
                                double learningRate            = Defaults.LearningRate)
     : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumnName), featureColumnName, exampleWeightColumnName, null, numberOfLeaves, numberOfTrees, minimumExampleCountPerLeaf, learningRate)
 {
     // Set the sigmoid parameter to the 2 * learning rate, for traditional FastTreeClassification loss
     _sigmoidParameter = 2.0 * FastTreeTrainerOptions.LearningRate;
 }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of <see cref="FastTreeBinaryClassificationTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="minDatapointsInLeaves">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
 /// <param name="numLeaves">The max number of leaves in each regression tree.</param>
 /// <param name="numTrees">Total number of decision trees to create in the ensemble.</param>
 internal FastTreeBinaryClassificationTrainer(IHostEnvironment env,
                                              string labelColumn        = DefaultColumnNames.Label,
                                              string featureColumn      = DefaultColumnNames.Features,
                                              string weightColumn       = null,
                                              int numLeaves             = Defaults.NumLeaves,
                                              int numTrees              = Defaults.NumTrees,
                                              int minDatapointsInLeaves = Defaults.MinDocumentsInLeaves,
                                              double learningRate       = Defaults.LearningRates)
     : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, numLeaves, numTrees, minDatapointsInLeaves, learningRate)
 {
     // Set the sigmoid parameter to the 2 * learning rate, for traditional FastTreeClassification loss
     _sigmoidParameter = 2.0 * FastTreeTrainerOptions.LearningRates;
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of <see cref="FastTreeBinaryClassificationTrainer"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="minDocumentsInLeafs">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
 /// <param name="numLeaves">The max number of leaves in each regression tree.</param>
 /// <param name="numTrees">Total number of decision trees to create in the ensemble.</param>
 /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
 public FastTreeBinaryClassificationTrainer(IHostEnvironment env,
                                            string labelColumn,
                                            string featureColumn,
                                            string weightColumn                 = null,
                                            int numLeaves                       = Defaults.NumLeaves,
                                            int numTrees                        = Defaults.NumTrees,
                                            int minDocumentsInLeafs             = Defaults.MinDocumentsInLeafs,
                                            double learningRate                 = Defaults.LearningRates,
                                            Action <Arguments> advancedSettings = null)
     : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, numLeaves, numTrees, minDocumentsInLeafs, learningRate, advancedSettings)
 {
     // Set the sigmoid parameter to the 2 * learning rate, for traditional FastTreeClassification loss
     _sigmoidParameter = 2.0 * Args.LearningRates;
 }
예제 #22
0
 /// <summary>
 /// Initializes a new instance of <see cref="FastForestClassification"/>
 /// </summary>
 /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="labelColumn">The name of the label column.</param>
 /// <param name="featureColumn">The name of the feature column.</param>
 /// <param name="weightColumn">The name for the column containing the initial weight.</param>
 /// <param name="numLeaves">The max number of leaves in each regression tree.</param>
 /// <param name="numTrees">Total number of decision trees to create in the ensemble.</param>
 /// <param name="minDocumentsInLeafs">The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data.</param>
 /// <param name="learningRate">The learning rate.</param>
 /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
 public FastForestClassification(IHostEnvironment env,
                                 string labelColumn,
                                 string featureColumn,
                                 string weightColumn                 = null,
                                 int numLeaves                       = Defaults.NumLeaves,
                                 int numTrees                        = Defaults.NumTrees,
                                 int minDocumentsInLeafs             = Defaults.MinDocumentsInLeafs,
                                 double learningRate                 = Defaults.LearningRates,
                                 Action <Arguments> advancedSettings = null)
     : base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, numLeaves, numTrees, minDocumentsInLeafs, learningRate, advancedSettings)
 {
     Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
     Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
 }
        /// <summary>
        /// Initializes a new instance of <see cref="SymSgdClassificationTrainer"/>
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        public SymSgdClassificationTrainer(IHostEnvironment env, string featureColumn, string labelColumn, Action <Arguments> advancedSettings = null)
            : base(Contracts.CheckRef(env, nameof(env)).Register(LoadNameValue), TrainerUtils.MakeR4VecFeature(featureColumn),
                   TrainerUtils.MakeBoolScalarLabel(labelColumn))
        {
            _args = new Arguments();

            // Apply the advanced args, if the user supplied any.
            _args.Check(Host);
            advancedSettings?.Invoke(_args);
            _args.FeatureColumn = featureColumn;
            _args.LabelColumn   = labelColumn;

            Info = new TrainerInfo();
        }
예제 #24
0
        /// <summary>
        /// Initializes a new instance of <see cref="LogisticRegression"/>
        /// </summary>
        /// <param name="env">The environment to use.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="weights">The name for the example weight column.</param>
        /// <param name="enforceNoNegativity">Enforce non-negative weights.</param>
        /// <param name="l1Weight">Weight of L1 regularizer term.</param>
        /// <param name="l2Weight">Weight of L2 regularizer term.</param>
        /// <param name="memorySize">Memory size for <see cref="LogisticRegression"/>. Low=faster, less accurate.</param>
        /// <param name="optimizationTolerance">Threshold for optimizer convergence.</param>
        internal LogisticRegression(IHostEnvironment env,
                                    string labelColumn          = DefaultColumnNames.Label,
                                    string featureColumn        = DefaultColumnNames.Features,
                                    string weights              = null,
                                    float l1Weight              = Options.Defaults.L1Weight,
                                    float l2Weight              = Options.Defaults.L2Weight,
                                    float optimizationTolerance = Options.Defaults.OptTol,
                                    int memorySize              = Options.Defaults.MemorySize,
                                    bool enforceNoNegativity    = Options.Defaults.EnforceNonNegativity)
            : base(env, featureColumn, TrainerUtils.MakeBoolScalarLabel(labelColumn), weights,
                   l1Weight, l2Weight, optimizationTolerance, memorySize, enforceNoNegativity)
        {
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));

            _posWeight        = 0;
            ShowTrainingStats = Args.ShowTrainingStats;
        }
        private protected CalibratorEstimatorBase(IHostEnvironment env,
                                                  ICalibratorTrainer calibratorTrainer, string labelColumn, string scoreColumn, string weightColumn)
        {
            Host = env;
            _calibratorTrainer = calibratorTrainer;

            if (!string.IsNullOrWhiteSpace(labelColumn))
            {
                LabelColumn = TrainerUtils.MakeBoolScalarLabel(labelColumn);
            }
            else
            {
                env.CheckParam(!calibratorTrainer.NeedsTraining, nameof(labelColumn), "For trained calibrators, " + nameof(labelColumn) + " must be specified.");
            }
            ScoreColumn = TrainerUtils.MakeR4ScalarColumn(scoreColumn); // Do we fanthom this being named anything else (renaming column)? Complete metadata?

            if (weightColumn != null)
            {
                WeightColumn = TrainerUtils.MakeR4ScalarWeightColumn(weightColumn);
            }
        }
        /// <summary>
        /// Initializes a new instance of <see cref="LightGbmBinaryTrainer"/>
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="weightColumn">The name for the column containing the initial weight.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        /// <param name="numLeaves">The number of leaves to use.</param>
        /// <param name="numBoostRound">Number of iterations.</param>
        /// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
        /// <param name="learningRate">The learning rate.</param>
        public LightGbmBinaryTrainer(IHostEnvironment env, string labelColumn, string featureColumn,
                                     string weightColumn = null,
                                     int?numLeaves       = null,
                                     int?minDataPerLeaf  = null,
                                     double?learningRate = null,
                                     int numBoostRound   = LightGbmArguments.Defaults.NumBoostRound,
                                     Action <LightGbmArguments> advancedSettings = null)
            : base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, advancedSettings)
        {
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));

            if (advancedSettings != null)
            {
                CheckArgsAndAdvancedSettingMismatch(numLeaves, minDataPerLeaf, learningRate, numBoostRound, new LightGbmArguments(), Args);
            }

            // override with the directly provided values
            Args.NumBoostRound  = numBoostRound;
            Args.NumLeaves      = numLeaves ?? Args.NumLeaves;
            Args.LearningRate   = learningRate ?? Args.LearningRate;
            Args.MinDataPerLeaf = minDataPerLeaf ?? Args.MinDataPerLeaf;
        }
예제 #27
0
        /// <summary>
        /// Initializes a new instance of <see cref="LogisticRegression"/>
        /// </summary>
        /// <param name="env">The environment to use.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="featureColumn">The name of the feature column.</param>
        /// <param name="weights">The name for the example weight column.</param>
        /// <param name="enforceNoNegativity">Enforce non-negative weights.</param>
        /// <param name="l1Weight">Weight of L1 regularizer term.</param>
        /// <param name="l2Weight">Weight of L2 regularizer term.</param>
        /// <param name="memorySize">Memory size for <see cref="LogisticRegression"/>. Lower=faster, less accurate.</param>
        /// <param name="optimizationTolerance">Threshold for optimizer convergence.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        public LogisticRegression(IHostEnvironment env,
                                  string labelColumn                  = DefaultColumnNames.Label,
                                  string featureColumn                = DefaultColumnNames.Features,
                                  string weights                      = null,
                                  float l1Weight                      = Arguments.Defaults.L1Weight,
                                  float l2Weight                      = Arguments.Defaults.L2Weight,
                                  float optimizationTolerance         = Arguments.Defaults.OptTol,
                                  int memorySize                      = Arguments.Defaults.MemorySize,
                                  bool enforceNoNegativity            = Arguments.Defaults.EnforceNonNegativity,
                                  Action <Arguments> advancedSettings = null)
            : base(env, featureColumn, TrainerUtils.MakeBoolScalarLabel(labelColumn), weights, advancedSettings,
                   l1Weight, l2Weight, optimizationTolerance, memorySize, enforceNoNegativity)
        {
            Host.CheckNonEmpty(featureColumn, nameof(featureColumn));
            Host.CheckNonEmpty(labelColumn, nameof(labelColumn));

            _posWeight        = 0;
            ShowTrainingStats = Args.ShowTrainingStats;

            if (ShowTrainingStats && Args.StdComputer == null)
            {
                Args.StdComputer = new ComputeLRTrainingStdImpl();
            }
        }
예제 #28
0
 internal LightGbmBinaryTrainer(IHostEnvironment env, Options options)
     : base(env, LoadNameValue, options, TrainerUtils.MakeBoolScalarLabel(options.LabelColumnName))
 {
     Contracts.CheckUserArg(options.Sigmoid > 0, nameof(Options.Sigmoid), "must be > 0.");
     Contracts.CheckUserArg(options.WeightOfPositiveExamples > 0, nameof(Options.WeightOfPositiveExamples), "must be > 0.");
 }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of <see cref="FastForestBinaryTrainer"/> by using the <see cref="Options"/> class.
 /// </summary>
 /// <param name="env">The instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="options">Algorithm advanced settings.</param>
 internal FastForestBinaryTrainer(IHostEnvironment env, Options options)
     : base(env, options, TrainerUtils.MakeBoolScalarLabel(options.LabelColumnName))
 {
 }
예제 #30
0
 /// <summary>
 /// Initializes a new instance of <see cref="FastForestClassification"/> by using the <see cref="Options"/> class.
 /// </summary>
 /// <param name="env">The instance of <see cref="IHostEnvironment"/>.</param>
 /// <param name="options">Algorithm advanced settings.</param>
 internal FastForestClassification(IHostEnvironment env, Options options)
     : base(env, options, TrainerUtils.MakeBoolScalarLabel(options.LabelColumn))
 {
 }